Code Monkey home page Code Monkey logo

Comments (2)

isaacs avatar isaacs commented on August 19, 2024 1

Good point, doc patch welcome or I'll get to it eventually. Brain dumping the answer here, unpolished.

You can do a case insensitive match on a case sensitive file system, though it's a bit less efficient, because it requires regexp comparisons in all path portions, instead of just those containing magic.

However, the reverse is not true; you cannot correctly do a case sensitive match on a case insensitive file system, because stat('FILE') will succeed if file exists, and there's no efficient and reliable way to determine the "real" canonical case across platforms.

As to "more or less results than expected": if the case sensitivity setting doesn't match the system (and the heuristic mentioned in the PR isn't triggered; for example, a case sensitive macOS fs), then if there's a file at foo/BAR,

  • Foo/* will not find a match, because readdir('Foo') fails
  • foo/Ba* will return foo/BAR because the pattern is converted to a case insensitive regexp
  • foo/Bar will not find a match.
  • Fo*/BAR will find the match

which, all together, is a confusing

In the other direction, where the fs is case insensitive, but we THINK it's case sensitive,

  • Foo/* will find the match
  • foo/Ba* will find not the match
  • foo/Bar will find the match
  • Fo*/BAR will not find the match

In other words:

  • incorrectly set as nocase:true
    • patterns match more than they should
    • strings match less than expected
    • Foo will find a match, but Fo* will not
  • incorrectly set as nocase:false
    • patterns match less than they should
    • Strings match more than expected
    • Fo* will not find a match, but Foo will

from node-glob.

ohadschn avatar ohadschn commented on August 19, 2024

@isaacs thank you for the quick and detailed response!

May I suggest breaking down the nocase setting to the following:

  1. fscase - overrides the node-glob inference of the FS case sensitivity. For this setting, keep the instruction should only be explicitly set when it is known that the filesystem's case sensitivity differs from the platform default.. It should be pretty self- explanatory that unexpected results are to be produced when glob is fed misleading information. I wouldn't even bother with the examples above, as I suspect they might do more harm (confusion) than good.
  2. matchCaseSensitivity - default to the resolved fscase. In case the latter is case-sensitive, allow case-insensitive matches (using the slower regex approach). In case the FS case is case-insensitive, throw an error if case-sensitive matches are requested. Again - I don't think any example is necessary, it should be clear that one can't ask the FS for something it doesn't support (if it doesn't discern between cases, you can't ask for case sensitivity in your matches).

from node-glob.

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.