Gossamer Forum
Home : Products : Gossamer Links : Discussions :

'eq' and extra spaces after 'and' in comparisons

Quote Reply
'eq' and extra spaces after 'and' in comparisons
Hi,


after a few hours of finding what is wrong with my if, else stuff in templates I have noticed that if extra spaces (more than one) is present in code after 'and' if statement will be false...


Example:

Code:

<%set foo = '1'%>
<%set bar = '1'%>



<%if foo eq '1' and bar eq '1'%>
foo bar, eq, NO extra spaces after and
<%endif%>
foo bar, eq, NO extra spaces after and


<%if foo eq '1' and bar eq '1'%>
foo bar, eq, extra spaces after and
<%endif%>
- NOTHING


<%if foo == '1' and == eq '1'%>
foo bar, ==, NO extra spaces after and
<%endif%>
foo bar, ==, NO extra spaces after and


<%if foo == '1' and == eq '1'%>
foo bar, ==, extra spaces after and
<%endif%>
foo bar, ==, extra spaces after and


It is working fine with '==' but not 'eq'


So, I pasted this example on my other site and it is WORKING FINE Crazy

Both sites runs GLinks 3.3.0 with all updates.
Can somebody confirm this?

Thanks!

Last edited by:

Payooo: Sep 12, 2010, 3:46 AM
Quote Reply
Re: [Payooo] 'eq' and extra spaces after 'and' in comparisons In reply to
<%if foo == '1' and == eq '1'%>

Thats not valid syntax ;)

Should be:

<%if foo == '1' and bar == eq '1'%>

Either way though - that does look like a little issue (gotta admit, I've never come across that one). Maybe GT could apply a fix for that at some point in the future Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] 'eq' and extra spaces after 'and' in comparisons In reply to
Hi Andy,

thanks for testing.
Sorry, after so much hours looking for error in my if/else stuf I posted wrong code Angelic
This one should be correct (I hope so).

Code:
<%set foo = '1'%>
<%set bar = '1'%>



<%if foo eq '1' and bar eq '1'%>
foo bar, eq, NO extra spaces after and
<%endif%>
foo bar, eq, NO extra spaces after and

<%if foo eq '1' and bar eq '1'%>
foo bar, eq, extra spaces after and
<%endif%>
- NOTHING


<%if foo == '1' and bar == '1'%>
foo bar, ==, NO extra spaces after and
<%endif%>
foo bar, ==, NO extra spaces after and



<%if foo == '1' and bar == '1'%>
foo bar, ==, extra spaces after and
<%endif%>
foo bar, ==, extra spaces after and



I noticed this error while trying to make my code more human readable, something like:

Code:
<%if
foo eq '1'
and
bar eq '1'
and
lots of other stuf...

%>
Quote Reply
Re: [Payooo] 'eq' and extra spaces after 'and' in comparisons In reply to
After looking for some clues, I checked compiled templates.

On site where everything is OK, compiled template contains:

# Generated: Sun Sep 12 07:39:56 2010, using GT::Template::Parser v2.153
parser_version => 2.170,


on faulty site:

# Generated: Sun Sep 12 07:45:37 2010, using GT::Template::Parser v2.159
parser_version => 2.170,


v2.153 != v2.159

But, both sites are on the latest GLinks version + all updates

Faulty one is old GLinks installation and upgraded and
OK is clean GLinks 3.3.0 installation with few updates/fixes


Now, even when I write this post I am afraid to hit enter after the and word Laugh

Last edited by:

Payooo: Sep 12, 2010, 5:54 AM
Quote Reply
Re: [Payooo] 'eq' and extra spaces after 'and' in comparisons In reply to
Me again...


OK site, part of compiled template:


$tags->{q{foo}} = do { my $none = (q{1}); \$none };
$tags->{q{bar}} = do { my $none = (q{1}); \$none };

if ($self->_get_var(q{foo}, { escape => 0, strict => 0, merge => 0 }) eq q{1} and $self->_get_var(q{bar}, { escape => 0, strict => 0, merge => 0 }) eq q{1}) {
$return .= q{
foo bar, eq, NO extra spaces after and
};
}

if ($self->_get_var(q{foo}, { escape => 0, strict => 0, merge => 0 }) eq q{1} and $self->_get_var(q{bar}, { escape => 0, strict => 0, merge => 0 }) eq q{1}) {
$return .= q{
foo bar, eq, extra spaces after and
};
}

if ($self->_get_var(q{foo}, { escape => 0, strict => 0, merge => 0 }) == q{1} and $self->_get_var(q{bar}, { escape => 0, strict => 0, merge => 0 }) == q{1}) {
$return .= q{
foo bar, ==, NO extra spaces after and
};
}

if ($self->_get_var(q{foo}, { escape => 0, strict => 0, merge => 0 }) == q{1} and $self->_get_var(q{bar}, { escape => 0, strict => 0, merge => 0 }) == q{1}) {
$return .= q{
foo bar, ==, extra spaces after and
};
}




Faulty site, part of compiled template:


$tags->{q{foo}} = do { my $none = (q{1}); (ref $none eq 'ARRAY' or ref $none eq 'HASH') ? $none : \$none };
$tags->{q{bar}} = do { my $none = (q{1}); (ref $none eq 'ARRAY' or ref $none eq 'HASH') ? $none : \$none };

if ($self->_get_var(q{foo}, { escape => 0, strict => 0, merge => 0 }) eq q{1} and $self->_get_var(q{bar}, { escape => 0, strict => 0, merge => 0 }) eq q{1}) {
$return .= q{
foo bar, eq, NO extra spaces after and
};
}

if ($self->_get_var(q{foo}, { escape => 0, strict => 0, merge => 0 }) eq q{1' and bar eq '1}) {
$return .= q{
foo bar, eq, extra spaces after and
};
}

if ($self->_get_var(q{foo}, { escape => 0, strict => 0, merge => 0 }) == q{1} and $self->_get_var(q{bar}, { escape => 0, strict => 0, merge => 0 }) == q{1}) {
$return .= q{
foo bar, ==, NO extra spaces after and
};
}

if ($self->_get_var(q{foo}, { escape => 0, strict => 0, merge => 0 }) == q{1' and bar == '1}) {
$return .= q{
foo bar, ==, extra spaces after and
};
}



I am not an expert but I can see that some serious stuff is missing Whistle
Quote Reply
Re: [Payooo] 'eq' and extra spaces after 'and' in comparisons In reply to
Your GT::Template::Parser is out of date - it should be using 2.159 on both.

However, you have found a bug (surprising no one has ran into this previously). Here's a small patch to GT/Template/Parser.pm to fix it:

Code:
--- GT/Template/Parser.pm 16 Aug 2008 22:48:22 -0000 2.159
+++ GT/Template/Parser.pm 13 Sep 2010 05:03:20 -0000
@@ -408,7 +408,7 @@
/xig;
my $buf = '';
for (@elements) {
- if (/^\s+(and|or)(?:\s*(not))?\s$/i) {
+ if (/^\s+(and|or)(?:\s*(not))?\s+$/i) {
push @tests, $buf if $buf;
$buf = '';

Adrian
Quote Reply
Re: [brewt] 'eq' and extra spaces after 'and' in comparisons In reply to
Hi,

thanks for checking this.


2.159 is on both sites
Both files are identical except:

On faulty site:
# CVS Info : 087,064,081,093,081

On OK site
# CVS Info : 087,068,085,094,083

So, what is v2.153 doing here? Crazy


Thanks for the fix.
Will it be available via update soon?