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

fix: escape newline/paragraph separators#36

Merged
joshwiens merged 1 commit into
webpack-contrib:masterfrom
bmeurer:patch-1
Oct 2, 2017
Merged

fix: escape newline/paragraph separators#36
joshwiens merged 1 commit into
webpack-contrib:masterfrom
bmeurer:patch-1

Conversation

@bmeurer

@bmeurer bmeurer commented Sep 27, 2017

Copy link
Copy Markdown
Contributor

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

jsf-clabot commented Sep 27, 2017

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@michael-ciniawsky michael-ciniawsky left a comment

Copy link
Copy Markdown
Member

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

bmeurer commented Sep 28, 2017

Copy link
Copy Markdown
Contributor Author

Anything missing to get this fixed?

@alexander-akait

Copy link
Copy Markdown
Member

@bmeurer what about jsesc?

@bmeurer

bmeurer commented Sep 28, 2017

Copy link
Copy Markdown
Contributor Author

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

@alexander-akait

Copy link
Copy Markdown
Member

@bmeurer can you investigate this?

@bmeurer

bmeurer commented Sep 28, 2017

Copy link
Copy Markdown
Contributor Author

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

@michael-ciniawsky michael-ciniawsky left a comment

Copy link
Copy Markdown
Member

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 ?

Comment thread index.js Outdated
return "module.exports = " + JSON.stringify(content);
content = JSON.stringify(content);
content = jsesc(content);
return 'module.exports = ' + content;

Copy link
Copy Markdown
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.

@mathiasbynens mathiasbynens Sep 29, 2017

Copy link
Copy Markdown

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

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

@mathiasbynens mathiasbynens Sep 29, 2017

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Member

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

@bmeurer

bmeurer commented Sep 29, 2017

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

bmeurer commented Sep 29, 2017

Copy link
Copy Markdown
Contributor Author

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

@michael-ciniawsky

Copy link
Copy Markdown
Member

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

@joshwiens

joshwiens commented Oct 1, 2017

Copy link
Copy Markdown
Member

@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

bmeurer commented Oct 1, 2017

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

bmeurer commented Oct 2, 2017

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

bmeurer commented Oct 2, 2017

Copy link
Copy Markdown
Contributor Author

Thanks.

@joshwiens

Copy link
Copy Markdown
Member

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

@bmeurer

bmeurer commented Oct 10, 2017

Copy link
Copy Markdown
Contributor Author

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

@joshwiens

Copy link
Copy Markdown
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