www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15074] New: std.path.globMatch and escaping [/]/{/}


          Issue ID: 15074
           Summary: std.path.globMatch and escaping [/]/{/}
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: thecybershadow gmail.com
                CC: bugzilla kyllingen.net

The documentation for std.path.globMatch says:

 Some characters of pattern have a special meaning (they are meta-characters)
 and *can't be escaped*.
In practice, this appears to be almost false. For * and ?, this can be done by "escaping" them using [*] and [?]. '[' should be escape-able as "[[]", and ']' shouldn't need to be escaped at all, except when in a [...] group, in which it could be escaped as "{[...],]}". The only case where I don't see a solution is escaping ']' in a [!...] group. Anyway, attempting to escape either [/]/{/} results in: core.exception.AssertError std\path.d(3002): Assertion failure The source of the unexplained assert is the function's contract: in { // Verify that pattern[] is valid import std.algorithm : balancedParens; assert(balancedParens(pattern, '[', ']', 0)); assert(balancedParens(pattern, '{', '}', 0)); } Two ways about this: 1) Remove this restriction, and instead improve the implementation to treat unterminated groups during actual parsing as either an error, or implicitly closed at the end of the pattern. Perhaps also add the above escaping tricks to the documentation. 2) Declare that any use case complicated enough that you need to escape meta-characters is a use case for std.regex, not std.path, and simply improve the assert statement to produce a meaningful error message. --
Sep 16 2015