Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

fix: escape newline/paragraph separators #36

Merged
merged 1 commit into from
Oct 2, 2017

Conversation

bmeurer
Copy link
Contributor

@bmeurer bmeurer commented Sep 27, 2017

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.

@jsf-clabot
Copy link

jsf-clabot commented Sep 27, 2017

CLA assistant check
All committers have signed the CLA.

index.js Outdated
return "module.exports = " + JSON.stringify(content);
content = JSON.stringify(content)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, use jsesc if you want more control over the output (e.g. if you want completely ASCII-safe output).

index.js Outdated
content = JSON.stringify(content)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');
return `module.exports = ${content}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return 'module.exports = ' + content;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the example of json-loader that @sokra pointed me to, where it's using template literals.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmeurer Thx

@michael-ciniawsky michael-ciniawsky added this to the 0.5.2 milestone Sep 27, 2017
@bmeurer
Copy link
Contributor Author

bmeurer commented Sep 28, 2017

Anything missing to get this fixed?

@alexander-akait
Copy link
Member

@bmeurer what about jsesc?

@bmeurer
Copy link
Contributor Author

bmeurer commented Sep 28, 2017

@evilebottnawi dunno. Maybe it makes sense to do this also for json-loader then.

@alexander-akait
Copy link
Member

@bmeurer can you investigate this?

@bmeurer
Copy link
Contributor Author

bmeurer commented Sep 28, 2017

@evilebottnawi done

bmeurer added a commit to bmeurer/json-loader that referenced this pull request Sep 28, 2017
Similar to webpack-contrib/raw-loader#36 we can
use jsesc here to deal with special characters in general.
Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need it ?

index.js Outdated
return "module.exports = " + JSON.stringify(content);
content = JSON.stringify(content);
content = jsesc(content);
return 'module.exports = ' + content;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

@mathiasbynens mathiasbynens Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If support for older environments is a concern, use jsesc v1.3.0: https://github.com/mathiasbynens/jsesc#support

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

index.js Outdated
.replace(/\u2029/g, '\\u2029');
return `module.exports = ${content}`;
content = JSON.stringify(content);
content = jsesc(content);
Copy link

@mathiasbynens mathiasbynens Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind reviewing json-loader #62 aswell please ?

@michael-ciniawsky
Copy link
Member

Adding status: blocked for now as we need to find consensus on #36 (comment) and following before moving on with this

@bmeurer
Copy link
Contributor Author

bmeurer commented Sep 29, 2017

How about we merge the initial fix then first, since that already fixes the fundamental bug. Whether or not going for jsesc can be solved in a follow-up PR?

@michael-ciniawsky
Copy link
Member

Yep, reverting is the best solution imho, we can do proper escaping with all the fuss evolved in a follow up if needed.

@bmeurer
Copy link
Contributor Author

bmeurer commented Sep 29, 2017

Ok, there you go. Just the simple bug fix.

@michael-ciniawsky
Copy link
Member

@d3viant0ne I case #25 lands soon this would be good to go aswell together with #10

@joshwiens
Copy link
Member

joshwiens commented Oct 1, 2017

@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

@bmeurer
Copy link
Contributor Author

bmeurer commented Oct 1, 2017

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.
@michael-ciniawsky
Copy link
Member

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

@bmeurer
Copy link
Contributor Author

bmeurer commented Oct 2, 2017

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?

@joshwiens
Copy link
Member

@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

@joshwiens joshwiens merged commit c972c92 into webpack-contrib:master Oct 2, 2017
@bmeurer
Copy link
Contributor Author

bmeurer commented Oct 2, 2017

Thanks.

@joshwiens
Copy link
Member

Alright, give me ~45 minutes to finish what I am working on & i'll get it out to npm.

@bmeurer
Copy link
Contributor Author

bmeurer commented Oct 10, 2017

Any chance to get this pushed to npm? It's really annoying to have to manually patch it all the time.

@joshwiens
Copy link
Member

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants