Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.perl on strings doesn't properly escape all sequences #330

Closed
p6rt opened this issue Sep 19, 2008 · 7 comments
Closed

.perl on strings doesn't properly escape all sequences #330

p6rt opened this issue Sep 19, 2008 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 19, 2008

Migrated from rt.perl.org#59068 (status was 'resolved')

Searchable as RT59068$

@p6rt
Copy link
Author

p6rt commented Sep 19, 2008

From @pmichaud

On Fri, Sep 19, 2008 at 11​:29​:30AM +0400, Andrew Shitov wrote​:

when I tried to use a dollar sign on a page, November failed to read
the modified page. It turns out that .perl method does not escape
dollars, thus
say '$'.perl
produces
"$"
while I expect to get
"\$"

Fail happens when the string containing non-escaped dollar is being eval-ed.

We probably also need to escape other items that might cause interpolation
in strings, such as {, @​, and % .

Also need to check that non-ASCII characters are properly encoded.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 21, 2008

From @moritz

Patrick R. Michaud wrote​:

On Sun, Sep 21, 2008 at 03​:34​:50PM +0200, Carl Mäsak wrote​:

Andrew (>)​:

It turns out that .perl method does not escape
dollars

Have you thought about reporting this via rakudobug@​perl.org?

It's already there as RT #​59068.

It would help if someone could describe all of the things that
need escaping, either as prose, Perl code, or text.

(CC'ed p6c and the ticket, hope it worked)

afaict the following characters needs escaping​:

  \ (escaping)
  " (string delimiter)
  $%@​& (sigils)
  { (closures)

(assembled from http://perlcabal.org/syn/S02.html#Literals )

Or in Perl 6 code​:

s​:g/<[\\$%@​&{"]>/\\$0/

Additionally some white spaces might be nice to escape, but I don't
think it's mandatory​: \n, \t.
Also non-ASCII-Codepoints could be replaced by their \x... or \c...
escape sequence.

Moritz

--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/

@p6rt
Copy link
Author

p6rt commented Sep 21, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 22, 2008

From @pmichaud

On Sun, Sep 21, 2008 at 10​:50​:22AM -0700, Moritz Lenz via RT wrote​:

Patrick R. Michaud wrote​:

It would help if someone could describe all of the things that
need escaping, either as prose, Perl code, or text.

(CC'ed p6c and the ticket, hope it worked)

afaict the following characters needs escaping​:

\\     \(escaping\)
    "     \(string delimiter\)
$%@&#8203;&  \(sigils\)
    \{     \(closures\)

(assembled from http://perlcabal.org/syn/S02.html#Literals )

I tried to implement this using the .trans method on strings,
but couldn't find the right set of arguments to pass to .trans
(I kept getting "Must pass a List of Pairs for transliteration"
exceptions.)

I think that .trans needs to be reworked -- once that is
done we can easily fix the .perl method for strings.

Pm

@p6rt
Copy link
Author

p6rt commented Sep 22, 2008

From @moritz

Patrick R. Michaud wrote​:

On Sun, Sep 21, 2008 at 10​:50​:22AM -0700, Moritz Lenz via RT wrote​:

Patrick R. Michaud wrote​:

It would help if someone could describe all of the things that
need escaping, either as prose, Perl code, or text.

(CC'ed p6c and the ticket, hope it worked)

afaict the following characters needs escaping​:

\\     \(escaping\)
    "     \(string delimiter\)
$%@&#8203;&  \(sigils\)
    \{     \(closures\)

(assembled from http://perlcabal.org/syn/S02.html#Literals )

I tried to implement this using the .trans method on strings,
but couldn't find the right set of arguments to pass to .trans
(I kept getting "Must pass a List of Pairs for transliteration"
exceptions.)

Something along these lines?

my $x = '
$scalar
@​array[]
%hash{}
&sub()
{ closure }
';

say $x.trans((
  ['\\', '"', '$', '%', '@​', '&', '{', "\n" ] =>
  ['\\\\', '\\"', '\\$', '\\%', '\\@​', '\\&', '\\{', '\\n']
));

# prints out
\n\$scalar\n\@​array[]\n\%hash\{}\n\&sub()\n\{ closure }\n

Cheers,
Moritz

--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/

@p6rt
Copy link
Author

p6rt commented Sep 22, 2008

From @pmichaud

Str.perl is now fixed in r31341.

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Sep 22, 2008

@pmichaud - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Sep 22, 2008
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant