cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

jsEncode is losing encoded characters in string. #207

Closed unscriptable closed 10 years ago

unscriptable commented 10 years ago

See this discussion: https://groups.google.com/d/msg/cujojs/Gt1Fof6tjOk/i5856nGUDWsJ

gehan commented 10 years ago

e.g. these string evaluate to the same when they are different

jsEncode('content: "\e738"')

"content: \"e738\""

jsEncode('content: "e738"')

"content: \"e738\""

unscriptable commented 10 years ago

Did a bit of research / testing. It seems that js converts all backslash-escaped characters it doesn't recognize to unescaped values:

> '\e738'.charCodeAt(0)
101

How could this possibly work in the original module(s)? Doesn't the js engine convert '\e738' to 'e738'?

-- J

gehan commented 10 years ago

Ah yes but the example I gave was a css file! I guess you need to make a cssEncode function with different encoding logic. On 13 Aug 2013 00:42, "John Hann" notifications@github.com wrote:

Did a bit of research / testing. It seems that js converts all backslash-escaped characters it doesn't recognize to unescaped values:

'\e738'.charCodeAt(0)101

How could this possibly work in the original module(s)? Doesn't the js engine convert '\e738' to 'e738'?

-- J

— Reply to this email directly or view it on GitHubhttps://github.com/cujojs/curl/issues/207#issuecomment-22534110 .

gehan commented 10 years ago

http://www.merttol.com/articles/code/introduction-to-css-escape-sequences.html

On 13 August 2013 07:40, Gehan Gonsalkorale gehan.g@gmail.com wrote:

Ah yes but the example I gave was a css file! I guess you need to make a cssEncode function with different encoding logic. On 13 Aug 2013 00:42, "John Hann" notifications@github.com wrote:

Did a bit of research / testing. It seems that js converts all backslash-escaped characters it doesn't recognize to unescaped values:

'\e738'.charCodeAt(0)101

How could this possibly work in the original module(s)? Doesn't the js engine convert '\e738' to 'e738'?

-- J

— Reply to this email directly or view it on GitHubhttps://github.com/cujojs/curl/issues/207#issuecomment-22534110 .

gehan commented 10 years ago

Here you go! \ is an escape character in JS so just need to handle that properly I think

https://github.com/cujojs/curl/pull/209