Coder Social home page Coder Social logo

Comments (8)

craigbarnes avatar craigbarnes commented on June 22, 2024

It seems if the braces are (incorrectly) determined to be "paired", all braces in the pattern get escaped and only represent themselves. That seems to prevent e.g. }*.{x,y} from matching }file.y. It also seems like it could cause false matches (and signed integer overflow?) as well, in the case of something like }foo{a,b, which has even (but not paired) braces.

from editorconfig-core-c.

xuhdev avatar xuhdev commented on June 22, 2024

Thanks for your many bug reports! How does #54 look to you?

from editorconfig-core-c.

craigbarnes avatar craigbarnes commented on June 22, 2024

It seems like #54 should fix the integer overflow and false matches, but it still seems to make the escaping more aggressive than necessary.

The approach I took is to find the last index at which there is a paired, closing brace and beyond that point just escape all braces. Closing braces before that point also get escaped (represent themselves) if brace_level == 0 (i.e. there's no opening brace to close).

The over-escaping issue is more of a question of semantics though and not necessarily a bug.

I haven't started using the editorconfig test cases yet because they're rather hard to separate from CMake and seem to require an implementation that retains all of the parsed properties as a dictionary instead of just cherry-picking the ones it's interested in (so it can use a struct instead). Otherwise, I'd start contributing some test cases to cover things like this.

from editorconfig-core-c.

craigbarnes avatar craigbarnes commented on June 22, 2024

Scratch what I said about integer overflow. The incorrect pairing check doesn't actually lead to overflow -- it just allows brace_level to possibly go negative, which seems like it would be harmless. I guess the real issue was just the possibility of emitting unpaired parentheses in the generated regex, which #54 seems to also solve.

from editorconfig-core-c.

craigbarnes avatar craigbarnes commented on June 22, 2024

I've been thinking about this some more and I'm starting to think your approach of "over-escaping" might actually be the best thing to do. Either that or just make patterns with invalid brace pairing match nothing (always return false).

I just noticed that my brace pairing check allows through unclosed braces if they are nested but the inner level is closed, e.g. {a,b{c,d{e}. It's not really obvious what the semantics should be in this case. The regex equivalent just causes regcomp() to return a REG_EPAREN error code. I guess if people supply badly formed patterns they can't really expect it to match anything.

tl;dr I think your PR #54 seems fine. My only remaining question is -- should badly paired braces just cause the pattern to match nothing at all instead?

from editorconfig-core-c.

xuhdev avatar xuhdev commented on June 22, 2024

I'm personally leaning toward not making incompatible changes unless there is a compelling reason. In this case, it would be keep unpaired curly braces match. What do you think?

from editorconfig-core-c.

craigbarnes avatar craigbarnes commented on June 22, 2024

If someone authors a pattern with unpaired braces by mistake, the net result is probably that it just doesn't match what they wanted it to (or anything at all). So long as there are no exploits in the implementation, either behaviour seems fine to me. I'll just copy whatever upstream decides on.

from editorconfig-core-c.

xuhdev avatar xuhdev commented on June 22, 2024

Fixed by #54

from editorconfig-core-c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.