Skip to content

Restrict strings beginning with quote should also ending with quote#13131

Merged
WindSoilder merged 7 commits intonushell:mainfrom
WindSoilder:strict_string
Jun 28, 2024
Merged

Restrict strings beginning with quote should also ending with quote#13131
WindSoilder merged 7 commits intonushell:mainfrom
WindSoilder:strict_string

Conversation

@WindSoilder
Copy link
Copy Markdown
Contributor

Description

Closes: #13010

It adds an additional check inside parse_string, and returns unbalanced quote if input string is unbalanced

User-Facing Changes

After this pr, the following is no longer allowed:

 "aaaa"aa
Error: nu::parser::unclosed_delimiter

  × Unclosed delimiter.
   ╭─[entry #1:1:1]
 1  "aaaa"aa
   · ────┬───
   ·     ╰── unclosed "
   ╰────
❯ 'aaa'aa
Error: nu::parser::unclosed_delimiter

  × Unclosed delimiter.
   ╭─[entry #2:1:1]
 1 │ 'aaa'aa
   · ───┬───
   ·    ╰── unclosed '
   ╰────

Tests + Formatting

Added 1 test

@WindSoilder WindSoilder added the deprecated:pr-language (deprecated: this label is too vague) This PR makes some language changes label Jun 11, 2024
@NotTheDr01ds
Copy link
Copy Markdown
Contributor

Technically a breaking change.

@WindSoilder WindSoilder added the notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes label Jun 13, 2024
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Jun 18, 2024

Are we ready to land this @WindSoilder?

@sholderbach
Copy link
Copy Markdown
Member

I am not sure if the logic you added @WindSoilder is specific to the case but for your example I think we could find a more specific error message that there is additional text after the closing delimiter. I think otherwise the unclosed delimiter message is a bit confusing if you encounter a longer string.

@WindSoilder
Copy link
Copy Markdown
Contributor Author

@sholderbach Do you have any good suggestions?
I have tried how python and rust report these error, they gives me something like this:

Python

> "asdfa"asdfa
  Cell In[1], line 1
    "asdfa"asdfa
           ^
SyntaxError: invalid syntax

Rust

error: suffixes on string literals are invalid
    --> crates/nu-parser/src/parser.rs:2836:17
     |
2836 |         let x = "asdfaf"asdfa;
     |                 ^^^^^^^^^^^^^ invalid suffix `asdfa`

It seems that they just say something is invalid

This reverts commit ef8530b.
It adds an additional check inside `parse_string`, and returns `unbalanced quote` if input string is unbalanced
@sholderbach
Copy link
Copy Markdown
Member

I think we can slightly improve on the Rust message with "invalid characters after closing delimiter" but only if that is emitted if we previously rule out the "missing closing delimiter"

@WindSoilder
Copy link
Copy Markdown
Contributor Author

Thanks! Here are the new error messages:

 "asdfasdf"asdfasdf
Error: nu::parser::extra_token_after_closing_delimiter

  × Invaild characters after closing delimiter
   ╭─[entry #1:1:11]
 1  "asdfasdf"asdfasdf
   ·           ────┬───
   ·               ╰── invalid characters
   ╰────
  help: Try removing them.
 'asdfasd'adsfadf
Error: nu::parser::extra_token_after_closing_delimiter

  × Invaild characters after closing delimiter
   ╭─[entry #2:1:10]
 1  'asdfasd'adsfadf
   ·          ───┬───
   ·             ╰── invalid characters
   ╰────
  help: Try removing them.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Jun 26, 2024

Are you ready to land this one @WindSoilder?

@WindSoilder
Copy link
Copy Markdown
Contributor Author

Yeah, sure. I think it's ok for now

@WindSoilder WindSoilder merged commit 5745233 into nushell:main Jun 28, 2024
@hustcer hustcer added this to the v0.96.0 milestone Jun 29, 2024
@WindSoilder WindSoilder deleted the strict_string branch July 15, 2024 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecated:pr-language (deprecated: this label is too vague) This PR makes some language changes notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strings beginning with quotes should not be interpreted as bare strings

5 participants