You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking at datetime/date.js and I'm not sure the escaping behaves quite as it should.
The relevant RegExp is: /\\?([a-z])/gi
It works fine for detecting if a letter is immediately preceded by a slash, but doesn't take into account slashes that are themselves escaped. For example a format string of "H\\\\i\\\\s", should produce a result like "17\57\31", but would in fact see both i and s as escaped even though they're not.
I've been working from the same basic code from jsfromhell.com, and reinventing the wheel a bit since somehow I missed this version of the PHP style date function. Anyway, the regexp I've been using is: /(\\\\)*(\\?([a-Z]))/gi
This will match any paired backslashes first, and only catch any remnant ones as escape sequences for a format letter. So then all you need to do is throw it into:
I dug a little deeper. It appears a backslash can escape any character (not just [a-z] and \\). If there's no character to escape (passing just \\ or trailing a string with \\), then PHP drops it from the result. Taking all of this into consideration, I believe the fix to the RegExp should be: /\\?(.?)/gi No other code would need to change.
I applied your fix Theriault as it appeared to work with the following test cases (not added as part of source given the already large number of examples) in addition to appearing to work normally with the regular flags:
I was looking at datetime/date.js and I'm not sure the escaping behaves quite as it should.
The relevant RegExp is:
/\\?([a-z])/gi
It works fine for detecting if a letter is immediately preceded by a slash, but doesn't take into account slashes that are themselves escaped. For example a format string of
"H\\\\i\\\\s"
, should produce a result like"17\57\31"
, but would in fact see both i and s as escaped even though they're not.I've been working from the same basic code from jsfromhell.com, and reinventing the wheel a bit since somehow I missed this version of the PHP style date function. Anyway, the regexp I've been using is:
/(\\\\)*(\\?([a-Z]))/gi
This will match any paired backslashes first, and only catch any remnant ones as escape sequences for a format letter. So then all you need to do is throw it into:
Hopefully I've not completely misunderstood!
The text was updated successfully, but these errors were encountered: