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

Behavior of Regular Expressions Contained in a Constant with a Sigil #5079

Closed
p6rt opened this issue Jan 23, 2016 · 7 comments
Closed

Behavior of Regular Expressions Contained in a Constant with a Sigil #5079

p6rt opened this issue Jan 23, 2016 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Jan 23, 2016

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

Searchable as RT127352$

@p6rt
Copy link
Author

p6rt commented Jan 23, 2016

From jpolanik@nc.rr.com

Constants are not required to have a sigil but apparently they may.

Unfortunately, when a constant with a sigil contains a regex pattern,
unpredictable results may occur.

The attached file show that a regex pattern that should detect the file
system separator ('/' or '\') yield incorrect results when contained in
a constant whose names contains a sigil but correct results otherwise.

Identical results were obtained on Linux (Ubuntu 12.04) and Mac OS X 10.10.5

Build information

Linux

$ perl6 -version
This is Rakudo version 2015.12 built on MoarVM version 2015.12
implementing Perl 6.c.

Mac

$ perl6 -version
This is Rakudo version 2015.12-176-gaefe2c2 built on MoarVM version
2015.12-29-g8079ca5 implementing Perl 6.c.

Thanks,

Joseph Polanik

@p6rt
Copy link
Author

p6rt commented Jan 23, 2016

From jpolanik@nc.rr.com

#!/usr/bin/env perl6

# Constants are not required to have a sigil. When they have a sigil and
# contain a regex, the results are unpredictable.

constant $sepreg = /(<[\\\/]>)/;
my $sepreg2 = /(<[\\\/]>)/;
constant sepreg3 = /(<[\\\/]>)/;

my $filenameW = "c​:\\g\\b.mp4";
my $filenameL = "/g/b.mp4";

say "============= Looking for a Windows separator​: \\";
# The match is made but $/ doesn't get populated
say "Testing regex as a constant with a sigil​: Windows separator";
if ($filenameW ~~ $sepreg) {
  say $/[0].Str;
}
else {
  say "No match for SEP";
}

# Gives correct result
say "Testing regex as a constant with no sigil​: Windows separator";
if ($filenameW ~~ sepreg3) {
  say $/[0].Str;
}
else {
  say "No match for SEP";
}

# Gives correct result
say "Testing regex as a lexical variable​: Windows separator";
if ($filenameW ~~ $sepreg2) {
  say $/[0].Str;
}
else {
  say "No match for SEP";
}

# Gives correct result
say "Testing regex as a string​: Windows separator";
if ($filenameW ~~ /(<[\\\/]>)/) {
  say $/[0].Str;
}

#
# Now try the same tests with a *nix file system
#
say "============= Looking for a *nix separator​: /";

# The match is made but $/ doesn't get populated
say "Testing regex as a constant with a sigil​: *nix separator​: Wrong Result";
if ($filenameL ~~ $sepreg) {
  say $/[0].Str;
}
else {
  say "No match for SEP";
}

# Gives correct result
say "Testing regex as a constant with no sigil​: *nix separator";
if ($filenameL ~~ sepreg3) {
  say $/[0].Str;
}
else {
  say "No match for SEP";
}

# Gives correct result
say "Testing regex as a lexical variable​: *nix separator";
if ($filenameL ~~ $sepreg2) {
  say $/[0].Str;
}
else {
  say "No match for SEP";
}

# Gives correct result
say "Testing regex as a string​: *nix separator";
if ($filenameL ~~ /(<[\\\/]>)/) {
  say $/[0].Str;
}

@p6rt
Copy link
Author

p6rt commented Aug 6, 2016

From @zoffixznet

Still present today​:

<Zoffix> m​: my $sepreg = rx/(<[\\/]>)/; my $filenameW = "c​:\\g\\b.mp4"; $filenameW ~~ $sepreg; say $/;
<camelia> rakudo-moar 589061​: OUTPUT«「\」␤ 0 => 「\」␤»
<Zoffix> m​: constant $sepreg = rx/(<[\\/]>)/; my $filenameW = "c​:\\g\\b.mp4"; $filenameW ~~ $sepreg; say $/;
<camelia> rakudo-moar 589061​: OUTPUT«Nil␤»
<Zoffix> m​: constant sepreg = rx/(<[\\/]>)/; my $filenameW = "c​:\\g\\b.mp4"; $filenameW ~~ sepreg; say $/;
<camelia> rakudo-moar 589061​: OUTPUT«「\」␤ 0 => 「\」␤»

@p6rt
Copy link
Author

p6rt commented Mar 13, 2018

From @dogbert17

On Fri, 05 Aug 2016 18​:04​:36 -0700, cpan@​zoffix.com wrote​:

Still present today​:

<Zoffix> m​: my $sepreg = rx/(<[\\/]>)/; my $filenameW =
"c​:\\g\\b.mp4"; $filenameW ~~ $sepreg; say $/;
<camelia> rakudo-moar 589061​: OUTPUT«「\」␤ 0 => 「\」␤»
<Zoffix> m​: constant $sepreg = rx/(<[\\/]>)/; my $filenameW =
"c​:\\g\\b.mp4"; $filenameW ~~ $sepreg; say $/;
<camelia> rakudo-moar 589061​: OUTPUT«Nil␤»
<Zoffix> m​: constant sepreg = rx/(<[\\/]>)/; my $filenameW =
"c​:\\g\\b.mp4"; $filenameW ~~ sepreg; say $/;
<camelia> rakudo-moar 589061​: OUTPUT«「\」␤ 0 => 「\」␤»

Fixed with commit rakudo/rakudo@5ac593e

@p6rt
Copy link
Author

p6rt commented Mar 13, 2018

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

@p6rt
Copy link
Author

p6rt commented Mar 22, 2018

From @dogbert17

On Tue, 13 Mar 2018 14​:50​:17 -0700, jan-olof.hendig@​bredband.net wrote​:

On Fri, 05 Aug 2016 18​:04​:36 -0700, cpan@​zoffix.com wrote​:

Still present today​:

<Zoffix> m​: my $sepreg = rx/(<[\\/]>)/; my $filenameW =
"c​:\\g\\b.mp4"; $filenameW ~~ $sepreg; say $/;
<camelia> rakudo-moar 589061​: OUTPUT«「\」␤ 0 => 「\」␤»
<Zoffix> m​: constant $sepreg = rx/(<[\\/]>)/; my $filenameW =
"c​:\\g\\b.mp4"; $filenameW ~~ $sepreg; say $/;
<camelia> rakudo-moar 589061​: OUTPUT«Nil␤»
<Zoffix> m​: constant sepreg = rx/(<[\\/]>)/; my $filenameW =
"c​:\\g\\b.mp4"; $filenameW ~~ sepreg; say $/;
<camelia> rakudo-moar 589061​: OUTPUT«「\」␤ 0 => 「\」␤»

Fixed with commit
rakudo/rakudo@5ac593e

Roast test added with commit Raku/roast@f2d422f

@p6rt
Copy link
Author

p6rt commented Mar 22, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant