File tree 2 files changed +16
-1
lines changed
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) {
53
53
content = [ content ] ;
54
54
links . forEach ( function ( link ) {
55
55
if ( ! loaderUtils . isUrlRequest ( link . value , root ) ) return ;
56
-
56
+
57
57
if ( link . value . indexOf ( 'mailto:' ) > - 1 ) return ;
58
58
59
59
var uri = url . parse ( link . value ) ;
@@ -129,6 +129,9 @@ module.exports = function(content) {
129
129
}
130
130
131
131
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, "\\\\\'" ) ;
132
135
content = compile ( '`' + content + '`' ) . code ;
133
136
} else {
134
137
content = JSON . stringify ( content ) ;
Original file line number Diff line number Diff line change @@ -71,6 +71,11 @@ describe("loader", function() {
71
71
'module.exports = "<!-- comment --><h3 customattr=\\"\\">#{number} {customer}</h3><p>{title}</p><!-- comment --><img src=\" + require("./image.png") + \" />";'
72
72
) ;
73
73
} ) ;
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
+ } )
74
79
75
80
it ( "should preserve comments and white spaces when minimizing (via webpack config property)" , function ( ) {
76
81
loader . call ( {
@@ -167,6 +172,13 @@ describe("loader", function() {
167
172
'module.exports = "<img src=\\"" + ("Hello " + (1 + 1)) + "\\">";'
168
173
) ;
169
174
} ) ;
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
+ } )
170
182
it ( "should enable interpolations when using interpolate=require flag and only require function to be translate" , function ( ) {
171
183
loader . call ( {
172
184
query : "?interpolate=require"
You can’t perform that action at this time.
0 commit comments