Closed remuladgryta closed 5 years ago
Since no other instruction may contain spaces, I think String#myshellsplit
could be altered to read as follows:
def myshellsplit
return self.scan /(?: # Match either
" # A string literal, which begins with "
(?: # and contains
\\. # any escaped character
| # OR
[^"\\] # any character which is not " or \
)* # of which there can be any number
" # finally string literals end with a "
| # or match a non-string instruction
\S+ # which are all composed of one or more
# non-whitespace characters
)/x
end
I tested this with the example programs and a quine I've been working on and they did not break, but I might be missing some edge case they don't cover.
Another bug that gets fixed by this implementation is that multiple consecutive spaces in a string literal get squashed down to one space. E.g.
"Hello world\n"
gets squashed to
"Hello world\n"
Thanks so much! Tell me more about that quine you're working on! :O
Sure! It's a pretty standard quine approach: take a string literal payload and print it once as a string literal and once as program code, making sure to add some cruft to the ends to make it all line up. Unfortunately it's not exactly readable code but the repo is available here: https://github.com/remuladgryta/legit-quine I might get around to adding comments, license, and the helper script I wrote to generate the payload string eventually. If not, feel free to use it under the MIT license.
Oh wow, awesome! :O When I tried to run it, I noticed that the tags being jumped to are not defined – instead, on GitHub, these seem to be branches? Does the program work for you?
I'm gonna give a presentation about legit tomorrow (in NYC, if you're near by any chance), and your contribution will be featured prominently! :D
Sorry, that's my mistake, I forgot to also push the tags. It should be remedied now. If it something's still amiss, here's a gist of the git commands: https://gist.github.com/remuladgryta/d8e93deedb9d02238d55f2efe87b6d1f
source legit-quine.sh && ruby /path/to/legit/interpreter.rb .
should output the same contents as legit-quine.sh
It appears that
String#myshellsplit
is not correctly tokenizing string literals containing quote characters.Parsing of string literals breaks whenever the literal contains an escaped quote character followed by space, but works as expected if there are an even number of escaped quotes before any space.
Steps to reproduce:
Running
interpreter.rb
on the repository outputsfoo said "bar"
as expected.git commit --allow-empty --amend -m "\"\\\" rab\\\" dias oof\""
(note the space beforerab
) Runninginterpreter.rb
on the repository now crashes withgit commit --allow-empty --amend -m "\"\\\"rab \\\" dias oof\""
(note the space afterrab
) Runninginterpreter.rb
on the repository now crashes with