[Issue 15074] New: std.path.globMatch and escaping [/]/{/}

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Sep 16 07:51:47 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15074

          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 at puremagic.com
          Reporter: thecybershadow at gmail.com
                CC: bugzilla at 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 at 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.

--


More information about the Digitalmars-d-bugs mailing list