-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cli: Fixes #5341: Ignore newline between quotes while spliting batch #5540
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ab1930b
Cli: Fixes #5341: Ignore newline between quotes while spliting batch …
kkoyung 61efbd1
separate splitting process to lib/string-utils.js, and add a test for it
kkoyung 45e5079
Merge branch 'laurent22:dev' into fix-multi-line-batch
kkoyung 071862f
update test cases for `splitCommandBatch()`
kkoyung 4b57792
change to use finite state machine in splitCommandBatch(), with an ex…
kkoyung 2f88f5b
minor changes on splitCommandBatch() and its corresponding test
kkoyung 4afb192
Merge branch 'laurent22:dev' into fix-multi-line-batch
kkoyung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,58 @@ function splitCommandString(command, options = null) { | |
return args; | ||
} | ||
|
||
function splitCommandBatch(commandBatch) { | ||
const commandLines = []; | ||
|
||
let state = 'command'; | ||
let current = ''; | ||
let quote = ''; | ||
for (let i = 0; i < commandBatch.length; i++) { | ||
const c = commandBatch[i]; | ||
|
||
if (state == 'command') { | ||
if (c == '\n') { | ||
commandLines.push(current); | ||
current = ''; | ||
} else if (c == '"' || c == '\'') { | ||
quote = c; | ||
current += c; | ||
state = 'quoted'; | ||
} else if (c == '\\') { | ||
current += c; | ||
if (i + 1 < commandBatch.length) { | ||
current += commandBatch[i + 1]; | ||
i++; | ||
} | ||
} else { | ||
current += c; | ||
} | ||
} else if (state == 'quoted') { | ||
if (c == quote) { | ||
quote = ''; | ||
current += c; | ||
state = 'command'; | ||
} else if (c == '\\') { | ||
current += c; | ||
if (i + 1 < commandBatch.length) { | ||
current += commandBatch[i + 1]; | ||
i++; | ||
} | ||
} else { | ||
current += c; | ||
} | ||
} | ||
} | ||
if (current.length > 0) { | ||
commandLines.push(current); | ||
} | ||
if (commandLines.length == 0) { | ||
commandLines.push(''); | ||
} | ||
|
||
return commandLines; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the update. In your function please use strict equality everywhere (=== and !==). All new code should use this. |
||
} | ||
laurent22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function padLeft(string, length, padString) { | ||
if (!string) return ''; | ||
|
||
|
@@ -307,4 +359,4 @@ function scriptType(s) { | |
return 'en'; | ||
} | ||
|
||
module.exports = Object.assign({ formatCssSize, camelCaseToDash, removeDiacritics, substrWithEllipsis, nextWhitespaceIndex, escapeFilename, wrap, splitCommandString, padLeft, toTitleCase, urlDecode, escapeHtml, surroundKeywords, scriptType, commandArgumentsToString }, stringUtilsCommon); | ||
module.exports = Object.assign({ formatCssSize, camelCaseToDash, removeDiacritics, substrWithEllipsis, nextWhitespaceIndex, escapeFilename, wrap, splitCommandString, splitCommandBatch, padLeft, toTitleCase, urlDecode, escapeHtml, surroundKeywords, scriptType, commandArgumentsToString }, stringUtilsCommon); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You split on EOL, which is OS specific, but your code only handle "\n". I'm fine if we only support "\n", but the tests should reflect that. So please set your own variable
const eol = "\n"
and use that.