-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Strings beginning with quotes should not be interpreted as bare strings #13010
Description
Related problem
Not sure whether to call this a bug or feature request. I feel it's a bug, but I'm going to start with "enhancement" and a maintainer can change the tag if you agree.
I was changing a raw-string to a single-quoted string today, and I forgot to remove the trailing #.
> let github_pat = 'github_pat_11AHWYXA0DDyPvy...'#
# Note: Not a valid GitHub PAT, of courseThe result, surprisingly, was a bare-string including the quotes and trailing #:
> $github_pat
'github_pat_11AHWYXA0DDyPvy...'#That, of course, caused the http get to fail authentication.
I was thinking this might be due to the raw-string parsing, but it turns out that any non-whitespace characters immediately following the closing quote will turn the quoted-string into a bare-string.
> 'abc'
abc
> 'abc'a
'abc'a
> "onetwo"3
"onetwo"3Except for raw-strings, which work as I'd expect:
> r#'abc'#abc
Error: nu::parser::unbalanced_delimiter
× Unbalanced delimiter.
╭─[entry #42:1:1]
1 │ r#'abc'#abc
· ─────┬─────
· ╰── unbalanced prefix # and postfix #
╰────Describe the solution you'd like
It seems to me that characters following a close-quote are almost certainly (as in my case) a syntax error and should result in an error condition.
Describe alternatives you've considered
I tend to prefer not receiving an error when there's a possibility that the syntax could be useful and intended, but in this case:
- I can't see where it might be intended
- If for some odd reason it was intended, we now have raw-strings, and those seem like a better (and safer) implementation.
Additional context and details
No response