Skip to content

Commit

Permalink
Special characters must be quoted in the query
Browse files Browse the repository at this point in the history
Closes #21
  • Loading branch information
joshuanapoli committed Dec 15, 2022
1 parent 1c28d45 commit daeb308
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ The CloudFormation YAML schema is supported. The input file can contain the Clou
- `!Split`
- `!Sub`

## Possible Issues

### Quoting Special Characters

Keys with hyphens and other special characters should be quoted in the query. For example, given an input file like this:
```yaml
foo-bar: baz
```

Then use a step definition like this:
```yaml
uses: CumulusDS/get-yaml-paths-action@v0.2.0
with:
file: file.yml
foobar: '"foo-bar"'
```

The query should be `"foo-bar"` to get the value of the `foo-bar` key. Without the quotes, the query would be interpreted as a numerical subtraction, which would result in an error.

# See Also

[get-json-paths-action](https://github.com/gr2m/get-json-paths-action)
Expand Down
1 change: 1 addition & 0 deletions env/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ provider:
qux:
- bar: hello
- bar: world
foo-bar: 7
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default async function main() {
core.setOutput(name, value);
}
} catch (error) {
console.log(error);
core.setFailed(error.message);
process.exit(1);
}
Expand Down
4 changes: 3 additions & 1 deletion test/unit/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ describe("main", () => {
INPUT_B: "provider.stage",
NOT_INPUT_C: "c",
INPUT_D: "qux[].bar",
INPUT_E: "foo"
INPUT_E: "foo",
INPUT_F: '"foo-bar"'
};
await main();
expect(core.setOutput).toHaveBeenCalledWith("a", "baz");
expect(core.setOutput).toHaveBeenCalledWith("b", "green");
expect(core.setOutput).toHaveBeenCalledWith("d", '["hello","world"]');
expect(core.setOutput).toHaveBeenCalledWith("e", '{"bar":"baz"}');
expect(core.setOutput).toHaveBeenCalledWith("f", 7);
});

it("calls setFailed when unsuccessful", async () => {
Expand Down
1 change: 1 addition & 0 deletions test/unit/readYaml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("readYaml", () => {
"foo": Object {
"bar": "baz",
},
"foo-bar": 7,
"provider": Object {
"stage": "green",
},
Expand Down

0 comments on commit daeb308

Please sign in to comment.