File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,16 @@ class SpriteHashPlugin {
2222 }
2323 }
2424
25+ /**
26+ * Escapes a string for safe use inside a PHP single-quoted string literal.
27+ *
28+ * @param {string } str Input string.
29+ * @return {string } Escaped string.
30+ */
31+ _escapePhpSingleQuoted ( str ) {
32+ return String ( str ) . replace ( / \\ / g, '\\\\' ) . replace ( / ' / g, "\\'" )
33+ }
34+
2535 /**
2636 * Formats a plain object as a PHP associative array string.
2737 *
@@ -30,8 +40,8 @@ class SpriteHashPlugin {
3040 */
3141 formatPhpArray ( obj ) {
3242 const entries = Object . entries ( obj ) . map ( ( [ key , value ] ) => {
33- const escapedKey = key . replace ( / ' / g , "\\'" )
34- const escapedValue = String ( value ) . replace ( / ' / g , "\\'" )
43+ const escapedKey = this . _escapePhpSingleQuoted ( key )
44+ const escapedValue = this . _escapePhpSingleQuoted ( value )
3545 return `\t'${ escapedKey } ' => '${ escapedValue } '`
3646 } )
3747 return `array(\n${ entries . join ( ',\n' ) } \n)`
You can’t perform that action at this time.
0 commit comments