Skip to content

Commit

Permalink
fix: warning message for TOML escape sequences (#3705)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Oct 11, 2021
1 parent f17ede7 commit ed16d0d
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/config/src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ const validateTomlBlackslashes = function (logs, configString, featureFlags) {
// This only applies to " and """ strings, not ' nor '''
// Also, """ strings can use trailing backslashes.
const INVALID_TOML_BLACKSLASH =
/= *(?:(?:""".*(?<!\\)(\\[^"\\btnfruU\n]).*""")|(?:"(?!").*(?<!\\)(\\[^"\\btnfruU]).*"))/su
/\n[a-zA-Z]+ *= *(?:(?:""".*(?<!\\)(\\[^"\\btnfruU\n]).*""")|(?:"(?!").*(?<!\\)(\\[^"\\btnfruU]).*"))/su

module.exports = { parseConfig, parseOptionalConfig }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
ignore = """
--test="value" \
"""
112 changes: 112 additions & 0 deletions packages/config/tests/parse/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,118 @@ Generated by [AVA](https://avajs.dev).
"siteInfo": {}␊
}`

## Configuration file - detecting invalid backslash sequences in TOML does not misinterpret equal signs

> Snapshot 1
`{␊
"accounts": [],␊
"addons": [],␊
"branch": "branch",␊
"buildDir": "packages/config/tests/parse/fixtures/parse_backslash_equal",␊
"config": {␊
"build": {␊
"environment": {},␊
"ignore": " --test=/"value/" ",␊
"processing": {␊
"css": {},␊
"html": {},␊
"images": {},␊
"js": {}␊
},␊
"publish": "packages/config/tests/parse/fixtures/parse_backslash_equal",␊
"publishOrigin": "default",␊
"services": {}␊
},␊
"functions": {␊
"*": {}␊
},␊
"headers": [],␊
"plugins": [],␊
"redirects": []␊
},␊
"configPath": "packages/config/tests/parse/fixtures/parse_backslash_equal/netlify.toml",␊
"context": "production",␊
"env": {␊
"BRANCH": {␊
"sources": [␊
"general"␊
],␊
"value": "branch"␊
},␊
"CACHED_COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"COMMIT_REF": {␊
"sources": [␊
"general"␊
],␊
"value": "HEXADECIMAL_ID"␊
},␊
"CONTEXT": {␊
"sources": [␊
"general"␊
],␊
"value": "production"␊
},␊
"GATSBY_TELEMETRY_DISABLED": {␊
"sources": [␊
"general"␊
],␊
"value": "1"␊
},␊
"HEAD": {␊
"sources": [␊
"general"␊
],␊
"value": "branch"␊
},␊
"LANG": {␊
"sources": [␊
"general"␊
],␊
"value": "en_US.UTF-8"␊
},␊
"LANGUAGE": {␊
"sources": [␊
"general"␊
],␊
"value": "en_US:en"␊
},␊
"LC_ALL": {␊
"sources": [␊
"general"␊
],␊
"value": "en_US.UTF-8"␊
},␊
"NETLIFY_LOCAL": {␊
"sources": [␊
"general"␊
],␊
"value": "true"␊
},␊
"NEXT_TELEMETRY_DISABLED": {␊
"sources": [␊
"general"␊
],␊
"value": "1"␊
},␊
"PULL_REQUEST": {␊
"sources": [␊
"general"␊
],␊
"value": "false"␊
}␊
},␊
"headersPath": "packages/config/tests/parse/fixtures/parse_backslash_equal/_headers",␊
"redirectsPath": "packages/config/tests/parse/fixtures/parse_backslash_equal/_redirects",␊
"repositoryRoot": "packages/config/tests/parse/fixtures/parse_backslash_equal",␊
"siteInfo": {}␊
}`

## Redirects - redirects file

> Snapshot 1
Expand Down
Binary file modified packages/config/tests/parse/snapshots/tests.js.snap
Binary file not shown.
6 changes: 6 additions & 0 deletions packages/config/tests/parse/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ test('Configuration file - invalid backslash sequences in multiline single quote
})
})

test('Configuration file - detecting invalid backslash sequences in TOML does not misinterpret equal signs', async (t) => {
await runFixture(t, 'parse_backslash_equal', {
flags: { featureFlags: { netlify_config_toml_backslash: true } },
})
})

test('Redirects - redirects file', async (t) => {
await runFixture(t, 'redirects_file')
})
Expand Down

0 comments on commit ed16d0d

Please sign in to comment.