fix: escape newline/paragraph separators#36
Conversation
| return "module.exports = " + JSON.stringify(content); | ||
| content = JSON.stringify(content) | ||
| .replace(/\u2028/g, '\\u2028') | ||
| .replace(/\u2029/g, '\\u2029'); |
There was a problem hiding this comment.
Alternatively, use jsesc if you want more control over the output (e.g. if you want completely ASCII-safe output).
| content = JSON.stringify(content) | ||
| .replace(/\u2028/g, '\\u2028') | ||
| .replace(/\u2029/g, '\\u2029'); | ||
| return `module.exports = ${content}`; |
There was a problem hiding this comment.
return 'module.exports = ' + content;There was a problem hiding this comment.
I was following the example of json-loader that @sokra pointed me to, where it's using template literals.
There was a problem hiding this comment.
@bmeurer - Just skip the template for now. As soon as this gets pulled into the webpack-defaults branch it will be converted to a template anyway.
|
Anything missing to get this fixed? |
|
@bmeurer what about |
|
@evilebottnawi dunno. Maybe it makes sense to do this also for |
|
@bmeurer can you investigate this? |
|
@evilebottnawi done |
Similar to webpack-contrib/raw-loader#36 we can use jsesc here to deal with special characters in general.
michael-ciniawsky
left a comment
There was a problem hiding this comment.
Do we really need it ?
| return "module.exports = " + JSON.stringify(content); | ||
| content = JSON.stringify(content); | ||
| content = jsesc(content); | ||
| return 'module.exports = ' + content; |
There was a problem hiding this comment.
If jsesc will be used we can go with a template literal here since the dependency requires node >= v4.0.0 anyways. node =< v4.0.0 is EOL, but this would be a SemVer Major for json-loader then.
There was a problem hiding this comment.
If support for older environments is a concern, use jsesc v1.3.0: https://github.com/mathiasbynens/jsesc#support
There was a problem hiding this comment.
Well it depends, since node =< v4.0.0 is EOL, it's more of a note and just needs consensus how to handle it (:label: patch/major && jsesc v1.3.0/latest). Let's wait for input of others on this matter :)
| .replace(/\u2029/g, '\\u2029'); | ||
| return `module.exports = ${content}`; | ||
| content = JSON.stringify(content); | ||
| content = jsesc(content); |
There was a problem hiding this comment.
Don’t use both! Doing so would cause over-escaping of \n etc.
In general, you can use jsesc(content, { json: true )) instead of JSON.stringify(content).
In this particular case, since we don’t really need JSON but rather a valid JS string literal, you could use jsesc(content, { wrap: true )) instead.
There was a problem hiding this comment.
Would you mind reviewing json-loader #62 aswell please ?
|
Adding |
|
How about we merge the initial fix then first, since that already fixes the fundamental bug. Whether or not going for |
|
Yep, reverting is the best solution imho, we can do proper escaping with all the fuss evolved in a follow up if needed. |
|
Ok, there you go. Just the simple bug fix. |
|
@michael-ciniawsky - Writing a few tests for this to go into #25 ( not that there is a lot to test ) but it would be nice to know if something broke completely. @bmeurer - Can you rebase this so I can get this merged & pulled into #25 |
|
Ok, I'm a bit lost here. I changed it back to the initial version (w/o the string template). Feel free to either merge this into master or into whatever branch you want. But it'd be nice to finally get this trivial bugfix in. |
Similar to webpack-contrib/json-loader#18 the `raw-loader` also needs to properly escape the special unicode characters, as otherwise `webpack` get's highly confused when it sees one of them.
|
Yeah... sry this got somehow derailed quite a bit, we should get this in as soon as possible, #25 should be/is ready just needs a someone from the release team to publish it |
|
Since #25 is unrelated/orthogonal to this, can you just merge the bugfix and release a fixed version? I don't want to sound rude, but given that it'd be just a single click to get the actual bug fixed, I don't quite understand why this is open for more than 4 days, with discussion about orthogonal/unrelated issues? |
|
@bmeurer - Next release is a semver: Major, this why all of this is going out as a single Major. I'll split the difference with you and put out a beta build for 1.0.0 |
|
Thanks. |
|
Alright, give me ~45 minutes to finish what I am working on & i'll get it out to npm. |
|
Any chance to get this pushed to npm? It's really annoying to have to manually patch it all the time. |
Similar to webpack-contrib/json-loader#18 the
raw-loaderalso needs to properly escape the special unicode characters, as otherwisewebpackget's highly confused when it sees one of them.