Description
openedon Jul 31, 2015
I'm sorry to say that the committee declined to accept this proposal as-is. In the end, the concern (largely driven by @erights, although others were sympathetic) was that escaping cannot be done in a way that is totally safe in all cases, even with the extended safe set. For example,
new RegExp("\\" + RegExp.escape("w"))
is a hazard. (It does not matter that "\\"
by itself is not a valid regex fragment. The above does not error to indicate that; it just silently creates a bug.)
Note that even if you attempted to correct this by escaping all initial characters, you then have
new RegExp("\\\\" + RegExp.escape("w"))
as a bug. @erights called this the "even-odd problem."
The general feeling was that to be completely safe you need a context-dependent join operation. The feeling was then that if author code wants to do unsafe escaping, the function is easy to write, but if something is going to be standardized, it must be completely safe. The idea that other languages are not held to this standard did not convince them, I'm sorry to say.
The committee recognized that you might not be willing to do work on a different, more complicated proposal. But, if you were interested, they think that a template string tag solution would be the best to investigate. Such a solution would be able to use the context of each insertion to do a safe join operation between any two fragments, instead of depending on string concatenation. Template strings can also be twisted to work in dynamic situations (e.g. those that this proposal would cover via new RegExp(pieces.map(RegExp.escape).join("/"))
) by directly calling the tag function, probably with an adapter to work through the awkwardness of the parameter form for template tags. So this would be strictly more powerful. This was also preferred (for reasons I don't really remember) to a building-block approach of e.g. RegExp.concat
plus RegExp.escape
(used as RegExp.concat("\\", RegExp.escape(x))
).
I'm pretty disappointed by this, and am sorry you and others sunk so much work into it with such an outcome. But, what can we do.
Activity