@yarnpkg/parsers
Advanced tools
Comparing version 3.0.0-rc.48.1 to 3.0.0-rc.49
@@ -79,18 +79,41 @@ "use strict"; | ||
exports.stringifyValueArgument = stringifyValueArgument; | ||
const ESCAPED_CONTROL_CHARS = new Map([ | ||
[`\f`, `\\f`], | ||
[`\n`, `\\n`], | ||
[`\r`, `\\r`], | ||
[`\t`, `\\t`], | ||
[`\v`, `\\v`], | ||
[`\0`, `\\0`], | ||
]); | ||
const ESCAPED_DBL_CHARS = new Map([ | ||
[`\\`, `\\\\`], | ||
[`$`, `\\$`], | ||
[`"`, `\\"`], | ||
...Array.from(ESCAPED_CONTROL_CHARS, ([c, replacement]) => { | ||
return [c, `"$'${replacement}'"`]; | ||
}), | ||
]); | ||
const getEscapedControlChar = (c) => { | ||
return ESCAPED_CONTROL_CHARS.get(c) ?? `\\x${c.charCodeAt(0).toString(16).padStart(2, `0`)}`; | ||
}; | ||
const getEscapedDblChar = (match) => { | ||
return ESCAPED_DBL_CHARS.get(match) ?? `"$'${getEscapedControlChar(match)}'"`; | ||
}; | ||
function stringifyArgumentSegment(argumentSegment) { | ||
const doubleQuoteIfRequested = (string, quote) => quote ? `"${string}"` : string; | ||
const doubleQuoteIfRequested = (string, quote) => quote | ||
? `"${string}"` | ||
: string; | ||
const quoteIfNeeded = (text) => { | ||
if (text === ``) | ||
return `""`; | ||
if (!text.match(/[(){}<>$|&; \t"']/)) | ||
return `''`; | ||
if (!text.match(/[()}<>$|&;"'\n\t ]/)) | ||
return text; | ||
return `$'${text | ||
.replace(/\\/g, `\\\\`) | ||
.replace(/'/g, `\\'`) | ||
.replace(/\f/g, `\\f`) | ||
.replace(/\n/g, `\\n`) | ||
.replace(/\r/g, `\\r`) | ||
.replace(/\t/g, `\\t`) | ||
.replace(/\v/g, `\\v`) | ||
.replace(/\0/g, `\\0`)}'`; | ||
if (!text.match(/['\t\p{C}]/u)) | ||
return `'${text}'`; | ||
if (!text.match(/'/)) { | ||
return `$'${text.replace(/[\t\p{C}]/u, getEscapedControlChar)}'`; | ||
} | ||
else { | ||
return `"${text.replace(/["$\t\p{C}]/u, getEscapedDblChar)}"`; | ||
} | ||
}; | ||
@@ -97,0 +120,0 @@ switch (argumentSegment.type) { |
{ | ||
"name": "@yarnpkg/parsers", | ||
"version": "3.0.0-rc.48.1", | ||
"version": "3.0.0-rc.49", | ||
"license": "BSD-2-Clause", | ||
@@ -43,3 +43,6 @@ "main": "./lib/index.js", | ||
}, | ||
"engines": { | ||
"node": ">=18.12.0" | ||
}, | ||
"stableVersion": "2.5.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
197476
6162