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

Initial support for regexp expressions #4

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@caipre

caipre commented Jan 27, 2015

This is a first pass at adding support for regular expressions within the expr attribute.

I'm not too familiar with this project or the perl toolchain, so my testing has been limited.
All tests print "ok", except a few errors that seem unrelated to these changes:

$ find ./t -maxdepth 1 -type f | while read file; do echo $file; perl -I ./lib $file; done |& less

And the new syntax works as desired:

$ cat regex.html
<%if expr="p1 like /foo/" %>
true
<%else %>
false
<%/if %>

<%if expr="p1 like /foobar/" %>
true
<%else %>
false
<%/if %>
$ cat htc.pl
use strict;
use warnings;

use Data::Dumper;
use HTML::Template::Compiled;

my $htc = HTML::Template::Compiled->new(
   filename => './test/regex.html',
   use_expressions => 1,
);

$htc->param(
   p1 => "foo",
   p2 => "nope"
);

print $htc->output;
$ perl -I ./lib ./htc.pl

true



false

Do let me know if there is a better way to run the test suite. If you're okay with these changes, I can add another test to cover this feature.

Note that this doesn't support deref vars. That shouldn't be much more difficult, just getting the recdescent rules in place.

Closes #2.

@perlpunk

This comment has been minimized.

Show comment
Hide comment
@perlpunk

perlpunk Feb 6, 2015

Owner

thanks, I'll have a look!

Owner

perlpunk commented Feb 6, 2015

thanks, I'll have a look!

@perlpunk

This comment has been minimized.

Show comment
Hide comment
@perlpunk

perlpunk Jul 19, 2015

Owner

thanks.
I see several issues, though.
I think the regex is to greedy.
Also one will be able to execute arbitrary perl code with this:

expr="string like /A\\\\/ || die 'oops';\#/"
expr="string like /@{[ system 'ls' ]}/"

Also regex modifiers like /i should be added.

I'll try to work on those issues.

Owner

perlpunk commented Jul 19, 2015

thanks.
I see several issues, though.
I think the regex is to greedy.
Also one will be able to execute arbitrary perl code with this:

expr="string like /A\\\\/ || die 'oops';\#/"
expr="string like /@{[ system 'ls' ]}/"

Also regex modifiers like /i should be added.

I'll try to work on those issues.

@caipre caipre closed this Dec 9, 2017

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