Skip to content

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

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

WindSoilder merged 7 commits into
nushell: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 language changes label Jun 11, 2024
@NotTheDr01ds

Copy link
Copy Markdown
Contributor

Technically a breaking change.

@WindSoilder WindSoilder added the notes:breaking-changes Noted in Breaking Changes section label Jun 13, 2024
@fdncred

fdncred commented Jun 18, 2024

Copy link
Copy Markdown
Contributor

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

fdncred commented Jun 26, 2024

Copy link
Copy Markdown
Contributor

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 language changes notes:breaking-changes Noted in Breaking Changes section

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