Bug 15074 – std.path.globMatch and escaping [/]/{/}

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-16T14:51:47Z
Last change time
2024-12-01T16:25:05Z
Assigned to
No Owner
Creator
Vladimir Panteleev
Moved to GitHub: phobos#10141 →

Comments

Comment #0 by dlang-bugzilla — 2015-09-16T14:51:47Z
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.
Comment #1 by post — 2015-09-28T06:35:26Z
(1) seems like the better solution to me. Personally, I'd prefer it if unterminated groups resulted in a parse error rather than being implicitly closed.
Comment #2 by robert.schadek — 2024-12-01T16:25:05Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10141 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB