Skip to content

Commit 71e34fe

Browse files
committed
safe json
1 parent a169410 commit 71e34fe

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

.github/workflows/check-redirects-on-rename.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ jobs:
6262
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6363
with:
6464
script: |
65-
const validationResultJson = `${{ steps.validate.outputs.validation_result }}`;
65+
// Use toJSON() to safely escape the JSON string for JavaScript interpolation
66+
// toJSON() will JSON-encode the string, so we need to parse it once to get the original JSON string,
67+
// then parse again to get the actual object
68+
const validationResultJsonString = ${{ toJSON(steps.validate.outputs.validation_result) }};
6669
let validationResult;
6770
try {
68-
validationResult = JSON.parse(validationResultJson);
71+
// First parse: convert from JSON-encoded string to original JSON string
72+
const jsonString = JSON.parse(validationResultJsonString);
73+
// Second parse: convert from JSON string to object
74+
validationResult = JSON.parse(jsonString);
6975
} catch (e) {
7076
console.error('Failed to parse validation result:', e);
7177
return;

0 commit comments

Comments
 (0)