forked from tools/josh
1
0
Fork 0

Allow equals in option values

Fixes #153.
This commit is contained in:
Florine W. Dekker 2020-12-07 17:43:52 +01:00
parent 6e55ffa217
commit fee631e216
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 7 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "fwdekker.com",
"version": "0.39.7",
"version": "0.39.8",
"description": "The source code of [my personal website](https://fwdekker.com/).",
"author": "Felix W. Dekker",
"browser": "dist/bundle.js",

View File

@ -126,12 +126,12 @@ export class InputParser {
}
const argsParts = arg.split("=");
if (argsParts.length === 0 || argsParts.length > 2)
if (argsParts.length === 0)
throw new IllegalArgumentError("Unexpected number of parts.");
if (argsParts[0].includes(" ") || argsParts[0].match(/[0-9]/))
break;
const value = argsParts.length === 1 ? null : argsParts[1];
const value = argsParts.length === 1 ? null : argsParts.slice(1).join("=");
if (argsParts[0].startsWith("--")) {
const key = argsParts[0].substr(2);
@ -169,9 +169,10 @@ export class Tokenizer {
* etc.
*
* Joining the returned array with spaces in between will give back the input string, disregarding extra whitespaces
* in between tokens. That is, no bytes are added, removed, or escaped in tokens.
* in between tokens. That is, no bytes are added, removed, or escaped inside tokens.
*
* @param input the string to tokenize
* @return the tokens
*/
tokenize(input: string): string[] {
const tokens: string[] = [];

View File

@ -210,8 +210,8 @@ describe("input parser", () => {
expect(parser.parseCommands("command -- -p")[0].options).to.not.have.own.property("-p");
});
it("throws an error if multiple equals signs occur", () => {
expect(() => parser.parseCommands("command -a=b=c")[0]).to.throw();
it("allows option values with an equals sign", () => {
expect(parser.parseCommands("command -a=b=c")[0].options["-a"]).to.equal("b=c");
});
});