Git Product home page Git Product logo

Comments (7)

bar-g avatar bar-g commented on August 26, 2024

It seems to be adding a backslash:

ysh ysh-0.20.0$ $'a\
> b'
  $'a\
  ^~
[ interactive ]:10: 'a\\\nb' not found
#                     ^^ why two?

Similar to here:

ysh ysh-0.20.0$ a'\'b
  a'\'b
  ^
[ interactive ]:9: 'a\\b' not found
#                    ^^ why two?

from oil.

bar-g avatar bar-g commented on August 26, 2024

[ interactive ]:9: 'a\\b' not found may this actually rather mean:
[ interactive ]:9: $'a\\b' not found, i.e. having searched for r'a\b'?
(could make some sense as the prompt is saying ...$)

For the first example, I guess I would have expected it to fail with "Invalid char escape" (or print ab as with double-quotes)

The problem seems to be there is never an "invalid char escape" error, nor an escaped (dropped) newline (sameas in double-quoted strings) with no amount of backslashes before a newline.

from oil.

andychu avatar andychu commented on August 26, 2024

It seems like this is identical to bash behavior

$ echo $'a\
> b'
a\
b


$ bin/ysh
ysh ysh-0.20.0$ echo $'a\
> b'
a\
b

The issue is that all strings in shell are MULTILINE strings. Single quotes, double quotes, etc.

\ at the end of the line is NOT an escaped newline -- that's only true outside quotes

from oil.

bar-g avatar bar-g commented on August 26, 2024

What you say does not explain why the single \ is parsed with parse_backslash off.

It's also against what happens within double-quotes. There the newline (and the backslash before it) gets consumed, and no "Invalid char escape" is necessary:

ysh ysh-0.20.0$ echo "a\
> b"
ab
ysh ysh-0.20.0$

Consuming is consistent with shell:

$ string="
        one \
        two \
        three \
       "
$ echo "$string"

        one         two         three 

Plus python seems parsing single backslashes in singe- and double-quotes just fine, and there is still a multifold of ways remaining to denote the same string using \b.

This makes me ask how well backed up and necessary is the breaking behavior?

And maybe it does make sense, to rather improve uniqueness of denoting strings with a strict_ option forbidding singelton-backslash-pairs -- instead of singleton-backslashes -- to maintain compatibility with shell and python.

from oil.

andychu avatar andychu commented on August 26, 2024

Oh I see! Yeah actually that is a good point.

We want backslashes to always be doubled so there is one way of writing it

I'm not sure why it is the way it is

from oil.

andychu avatar andychu commented on August 26, 2024

This is fixed - we now consistently disallow the single backslash then newline in YSH (details in commit description)

Will be out with the next release

Great testing, thank you!

from oil.

andychu avatar andychu commented on August 26, 2024

Released! https://www.oilshell.org/blog/2024/03/release-0.21.0.html

from oil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.