Repository navigation
Treat any backslash-escaped character in a glob as a literal - #248
Merged
Merged
Conversation
translate() only honoured an escape for } and , inside braces. An
escaped *, ?, [ or { was still translated as a glob operator, and the
escape then carried over to the next character. So [a\*] matched
"abc", and [\{a] produced an unbalanced regexp that made every lookup
in that directory fail with "error parsing regexp: missing closing )".
Emit the character after a backslash literally before looking at
glob syntax, as the spec describes and the C and JavaScript cores do.
Member
|
@gyanu2507 thanks; we've got too many disabled tests. |
Contributor
Author
|
@greut fair point. This PR does not add any new skipped cases: I am happy to take a follow-up that tries to enable some of the currently skipped parser cases ( |
greut
approved these changes
Oct 31, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The spec says special characters in a section name can be escaped with a backslash so they aren't treated as glob syntax.
translate()only honoured that for}and,inside braces. Any other escaped character went through the normal glob handling, and the escape flag then stayed set for the next character.Two visible effects:
editorconfig /tmp/x/abcprintsk=v, becausea\*becomesa[^/]*. It should only match a file literally nameda*.Every lookup in that directory fails:
So one escaped
{(or[) in a section name stops the whole.editorconfigfrom applying. The C core (0.12.11) and editorconfig-core-js handle both cases as literals.Change
At the top of the loop in
translate(), a character that follows a backslash is written withregexp.QuoteMetaand the globswitchis skipped. TheisEscapedchecks inside the},,and default cases could no longer be reached, so I removed them and gave\\its own case. That also let themaintidxentry come out of thenolintcomment, sincenolintlintflagged it as unused.One existing expectation in
TestTranslatechanges:{e,\},f}now translates to(?:e|\}|f)instead of(?:e|}|f). Both match the same strings.Tests
TestTranslate: new cases for escaped*,?,{and\.TestFnmatchCaseEscapes: checks thata\*,a\?,\{a,\{a,b}anda\[b]match the literal name and not a wildcard match. Without the change infnmatch.go, 7 of these subtests fail.go test ./...andmake test-core(176 of 176) pass.golangci-lint runreports the same 10 issues as onmasterand nothing new.I found this by comparing this core, the C core and the JS core on random section names and paths. After this change, the only differences left with the C core are cases where Go and JS agree with each other, like reversed numeric ranges such as
{12..1}.