Comments (7)
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.
[ 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.
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.
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.
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.
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.
Released! https://www.oilshell.org/blog/2024/03/release-0.21.0.html
from oil.
Related Issues (20)
- Abort with += on missing dict key
- intermittent crash running amd-test script -- reproducible in dbg, opt HOT 4
- OpenBSD doesn't have RLIMIT_AS HOT 1
- Add pp [x + 42] to print an expression and its value - like Rust dbg!() HOT 3
- github URL pastebin HOT 8
- bash allows pasting multi-line code snippets, but OSH/YSH don't HOT 3
- allow backspace from multiline expressions HOT 1
- allow any custom prompts HOT 2
- typeof / reflection / assign results of '=' HOT 3
- emoji/unicode identifiers
- Setting up GNU readline history HOT 1
- 'view latest' released version in documentation - because old links are often surfaced HOT 1
- crash in parsing return HOT 1
- BashArray could have a sparse representation (ble.sh)
- bash SHELLOPTS and BASHOPTS support
- pitfall - IFS= read x doesn't set x (read --raw-line or for <> loop instead) HOT 6
- Fatal error when closing stderr on a non-fatal error
- nixos defaultUserShell HOT 4
- `json read` unexpectedly parses `123\x00` HOT 8
- Sudo in dev builds isn't very necessary HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oil.