File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ module.exports = function(content) {
5353 content = [ content ] ;
5454 links . forEach ( function ( link ) {
5555 if ( ! loaderUtils . isUrlRequest ( link . value , root ) ) return ;
56-
56+
5757 if ( link . value . indexOf ( 'mailto:' ) > - 1 ) return ;
5858
5959 var uri = url . parse ( link . value ) ;
@@ -129,6 +129,9 @@ module.exports = function(content) {
129129 }
130130
131131 if ( config . interpolate && config . interpolate !== 'require' ) {
132+ // Double escape quotes so that they are not unescaped completely in the template string
133+ content = content . replace ( / \\ " / g, "\\\\\"" ) ;
134+ content = content . replace ( / \\ ' / g, "\\\\\'" ) ;
132135 content = compile ( '`' + content + '`' ) . code ;
133136 } else {
134137 content = JSON . stringify ( content ) ;
Original file line number Diff line number Diff line change @@ -71,6 +71,11 @@ describe("loader", function() {
7171 'module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src=\" + require("./image.png") + \" />";'
7272 ) ;
7373 } ) ;
74+ it ( "should preserve escaped quotes" , function ( ) {
75+ loader . call ( { } , '<script>{"json": "with \\"quotes\\" in value"}</script>' ) . should . be . eql (
76+ 'module.exports = "<script>{\\\"json\\\": \\\"with \\\\\\\"quotes\\\\\\\" in value\\\"}</script>";'
77+ ) ;
78+ } )
7479
7580 it ( "should preserve comments and white spaces when minimizing (via webpack config property)" , function ( ) {
7681 loader . call ( {
@@ -167,6 +172,13 @@ describe("loader", function() {
167172 'module.exports = "<img src=\\"" + ("Hello " + (1 + 1)) + "\\">";'
168173 ) ;
169174 } ) ;
175+ it ( "should not change handling of quotes when interpolation is enabled" , function ( ) {
176+ loader . call ( {
177+ query : "?interpolate"
178+ } , '<script>{"json": "with \\"quotes\\" in value"}</script>' ) . should . be . eql (
179+ 'module.exports = "<script>{\\\"json\\\": \\\"with \\\\\\\"quotes\\\\\\\" in value\\\"}</script>";'
180+ ) ;
181+ } )
170182 it ( "should enable interpolations when using interpolate=require flag and only require function to be translate" , function ( ) {
171183 loader . call ( {
172184 query : "?interpolate=require"
You can’t perform that action at this time.
0 commit comments