Skip to content

Strings beginning with quotes should not be interpreted as bare strings #13010

Closed

Description

@NotTheDr01ds

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 course

The 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"3

Except 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:

  1. I can't see where it might be intended
  2. 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

Activity

  1. added
    category:enhancement
    status:needs-triage
    on May 30, 2024
  2. fdncred commented on May 30, 2024

    @fdncred
    Contributor

    Interesting. @WindSoilder any thoughts on this? I'm guessing we should be able to see an end # without a beginning r# and complain about it. Agreed that this seems related to raw_string_literals but may not be based on your other findings, which are definitely weird looking.

  3. NotTheDr01ds commented on May 30, 2024

    @NotTheDr01ds
    ContributorAuthor

    I'm guessing we should be able to see an end # without a beginning r# and complain about it.

    But that would leave all the other trailing character-issues in place.

    What I'm basically proposing is any string that starts with a single or double-quote, but doesn't end with one, should be an error, not a bare-string. Raw-strings do work like this, already. They're great - And thank you again for that syntax.

  4. kaathewisegit commented on May 31, 2024

    @kaathewisegit
    Contributor

    I've encountered it a couple of times, and it confused me, too. Strings have two completely separate semantics depending on how the quotes are balanced.

    ~> "a"
    a
    ~> "a"b
    "a"b
    ~> "a""
    	# can't enter, starts newline
    ~> "a"""
    a""
    ~> ""a""
    "a"
    ~> " "a
    " "a
    ~> " "a""
     "a"
    ~> " "a ""
    Error: nu::parser::parse_mismatch
    
      × Parse mismatch during operation.
       ╭─[entry #1:1:6]
     1 │ " "a ""
       ·      ─┬
       ·       ╰── expected operator
       ╰────
  5. WindSoilder commented on May 31, 2024

    @WindSoilder
    Contributor

    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.

    It makes sense to me, I can not see a case that we should interpreted it as bare strings.

  6. added a commit that references this issue on Jun 28, 2024
    5745233
  7. added this to the v0.96.0 milestone on Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:enhancementstatus:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions