Opened 15 years ago
Last modified 10 years ago
#4763 closed defect
[CLA] [patch] dojo.substitute() returns undefined for unknown place holders — at Version 9
Reported by: | wolfram | Owned by: | alex |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Core | Version: | 1.0 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description (last modified by )
Currently dojo.string.substitute works like this:
>>> dojo.string.substitute("${i} is not defined, but ${x} is", {x:"'this'"}); undefined
but it should do this imho
>>> dojo.string.substitute("${i} is not defined, but ${x} is", {x:"'this'"}); ${i} is not defined, but 'this' is
My usecase: I am doing replacement in multiple steps and want to replace only when the right data are given.
Change History (11)
Changed 15 years ago by
Attachment: | string_substitute.patch added |
---|
comment:1 Changed 15 years ago by
comment:2 Changed 15 years ago by
what do you mean by "both ways" does that not require a flag? Using the patch i provided would make it at least work like the String.replace method works ... just another thought
comment:3 Changed 15 years ago by
and its currently not throwing an exception or anything, it just returns undefined, which imho feels a bit odd
comment:4 follow-up: 5 Changed 15 years ago by
it throws for me, in trunk at least. What browser are you on?
dojo.string.substitute("${i} is not defined, but ${x} is", {x:"'this'"});
TypeError?: value has no properties
If a missing param doesn't throw, it's currently a bug.
The documented behavior was intentional, and different from the generic string.replace. The theory was that most of the time, it's a one-shot deal, and it's a very common error to miss a substitution or misspell something, so it's useful to flag a mismatch of data and code (IMO)
In your use case, is it possible/reasonable to accumulate the hash using a mixin or beget pattern and process it when you're ready?
Changed 15 years ago by
Attachment: | additional_tests_for_substitute_error_case.diff added |
---|
This patch adds tests for dojo.string.substitue() that show the current misbehaviour
comment:5 Changed 15 years ago by
Version: | 0.9 → 1.0 |
---|
Replying to peller:
it throws for me, in trunk at least. What browser are you on?
dojo.string.substitute("${i} is not defined, but ${x} is", {x:"'this'"});
TypeError?: value has no properties
If a missing param doesn't throw, it's currently a bug.
The documented behavior was intentional, and different from the generic string.replace. The theory was that most of the time, it's a one-shot deal, and it's a very common error to miss a substitution or misspell something, so it's useful to flag a mismatch of data and code (IMO)
In your use case, is it possible/reasonable to accumulate the hash using a mixin or beget pattern and process it when you're ready?
try the patch i just added, it fails for me. and the fault is the two additional test cases i added. can you confirm that?
comment:6 Changed 15 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
You're right, there should be a test case for this. I will incorporate your patch, thanks.
The assertError case works fine. However, if you call assertFalse on code that throws an exception, the exception will throw through the assert and doh will will report an error. In other words, assertFalse assumes a false result without an error, so I don't think the first test case is valid.
comment:9 Changed 10 years ago by
Description: | modified (diff) |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
Actually above checkin was for #3763.
this conflicts with the stated behavior that dojo.string.substitutes throws if a match fails. This was done deliberately to flag cases where strings and code are mismatched that might otherwise go unnoticed by the developer. We can revisit that decision, but I don't think we can have it both ways (we don't want another flag here, do we?)