Use of quotes in attributes with expressions
Status: Pre-Alpha
Brought to you by:
jeffmoore
The current expression syntax e.g.;
{$"this is a constant"}
Causes a problem for HTMLSax, when used in attributes e.g.;
<tag attribute="{$"this is a constant"}">
This _should_ work;
<tag attribute="{$'this is a constant'}">
Or this _should_ work;
<tag attribute='{$"this is a constant"}'>
But might be easier for all if we made the syntax
something like;
{$[this is a constant]}
Square brackets.
Logged In: NO
The problem now exists also with the quoted parameters of
the filters. Before the last CVS update it was possible to
set double quote paramters inside html attributes with
double quotes... right now it's broken.
Logged In: NO
A little addition: it still works but only if you have only
one attribute (with filters) per tag; with two or more is
broken.
Logged In: NO
I've added some tests to clip_filter.test.php to show the
bugs reported here. It is also visible a bug that I've
already tried to explain but I weren't able to show in
practice. As you can see the filter inside an attribute
produce an unwanted extra space.
<?php
//--------------------------------------------------------------------------------
// Copyright 2004 Procata, Inc.
// Released under the LGPL license
(http://www.gnu.org/copyleft/lesser.html)
//--------------------------------------------------------------------------------
/**
* @package WACT_TESTS
* @author Jason E. Sweat < jsweat_php AT yahoo DOT com >
* @version $Id: clip_filter.test.php,v 1.2 2004/06/15
19:38:51 jsweat Exp $
*/
require_once WACT_ROOT . '/template/template.inc.php';
/**
* @package WACT_TESTS
* @author Jason E. Sweat < jsweat_php AT yahoo DOT com >
*/
class TemplateClipFilterTestCase extends UnitTestCase {
function TemplateRpnFilterTestCase($name =
'TemplateClipFilterTestCase') {
$this->UnitTestCase($name);
}
function testSimpleClipVar() {
$Template = '{$val|clip:5}';
RegisterTestingTemplate('/template/filter/clipvar.html',
$Template);
$Page =& new Template('/template/filter/clipvar.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, 'abcde');
}
function testSimpleClipLiteral() {
$Template = '<core:set str="abcdefgh" />{$str|clip:5}';
RegisterTestingTemplate('/template/filter/clipstr.html',
$Template);
$Page =& new Template('/template/filter/clipstr.html');
$output = $Page->capture();
$this->assertEqual($output, 'abcde');
}
function testSimpleClipVarStart() {
$Template = '{$val|clip:5,2}';
RegisterTestingTemplate('/template/filter/clipvarstart.html',
$Template);
$Page =& new
Template('/template/filter/clipvarstart.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, 'cdefg');
}
function testSimpleClipLiteralStart() {
$Template = '<core:set str="abcdefgh"
/>{$str|clip:5,2}';
RegisterTestingTemplate('/template/filter/clipstrstart.html',
$Template);
$Page =& new
Template('/template/filter/clipstrstart.html');
$output = $Page->capture();
$this->assertEqual($output, 'cdefg');
}
function testSimpleClipVarSuffix() {
$Template = '{$val|clip:5,0,"..."}
{$val|clip:12,0,"..."}';
RegisterTestingTemplate('/template/filter/clipvarsuf.html',
$Template);
$Page =& new
Template('/template/filter/clipvarsuf.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, 'abcde... abcdefgh');
}
function testSimpleClipLiteralSuffix() {
$Template = '<core:set str="abcdefgh"
/>{$str|clip:5,0,"..."} {$str|clip:12,0,"..."}';
RegisterTestingTemplate('/template/filter/clipstrsuf.html',
$Template);
$Page =& new
Template('/template/filter/clipstrsuf.html');
$output = $Page->capture();
$this->assertEqual($output, 'abcde... abcdefgh');
}
function testSimpleClipLiteralLenVarSuffix() {
$Template = '<core:set str="abcdefgh"
/>{$str|clip:len,0,"..."} {$str|clip:len2,0,"..."}';
RegisterTestingTemplate('/template/filter/clipstrsuflenvar.html',
$Template);
$Page =& new
Template('/template/filter/clipstrsuflenvar.html');
$Page->Set('len', 5);
$Page->Set('len2', 12);
$output = $Page->capture();
$this->assertEqual($output, 'abcde... abcdefgh');
}
function testLongStringWordBoundary() {
$Template = '{$val|clip:35,0,"...","n"}
{$val|clip:35,0,"...","y"}';
RegisterTestingTemplate('/template/filter/clipvarwordbound.html',
$Template);
$Page =& new
Template('/template/filter/clipvarwordbound.html');
$Page->Set('val','Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. In auctor sem vitae ante.');
$output = $Page->capture();
$this->assertEqual($output, 'Lorem ipsum dolor sit
amet, consect... Lorem ipsum dolor sit amet, consectetuer...');
}
function testLongLiteralStringWordBoundary() {
$Template = '<core:set str="Lorem ipsum dolor sit
amet, consectetuer adipiscing elit. In auctor sem vitae
ante." />'
.'{$str|clip:35,0,"...","No"}
{$str|clip:35,0,"...","Yes"}';
RegisterTestingTemplate('/template/filter/clipstrwordbound.html',
$Template);
$Page =& new
Template('/template/filter/clipstrwordbound.html');
$output = $Page->capture();
$this->assertEqual($output, 'Lorem ipsum dolor sit
amet, consect... Lorem ipsum dolor sit amet, consectetuer...');
}
function testOneAttributeDoubleQuoteVar() {
$Template = '<img src="img.gif"
alt="{$val|clip:5,0,"..."}"/>';
RegisterTestingTemplate('/template/filter/testoneattributedoublequote.html',
$Template);
$Page =& new
Template('/template/filter/testoneattributedoublequote.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, '<img src="img.gif"
alt="abcde..."/>');
}
/*
// THIS TEST WILL CAUSE A TIMEOUT ERROR
function testOneAttributeSingleQuoteVar() {
$Template = '<img src=\'img.gif\'
alt=\'{'.'$val|clip:5,0,\'...\'}\'/>';
RegisterTestingTemplate('/template/filter/testoneattributesinglequote.html',
$Template);
$Page =& new
Template('/template/filter/testoneattributesinglequote.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, "<img src='img.gif'
alt='abcde...'/>");
}
*/
function testOneAttributeMixedQuote1Var() {
$Template = '<img src="img.gif"
alt="{$val|clip:5,0,\'...\'}"/>';
RegisterTestingTemplate('/template/filter/testoneattributemixedquote1.html',
$Template);
$Page =& new
Template('/template/filter/testoneattributemixedquote1.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, '<img src="img.gif"
alt="abcde..."/>');
}
function testOneAttributeMixedQuote2Var() {
$Template = '<img src=\'img.gif\'
alt=\'{'.'$val|clip:5,0,"..."}\'/>';
RegisterTestingTemplate('/template/filter/testoneattributemixedquote2.html',
$Template);
$Page =& new
Template('/template/filter/testoneattributemixedquote2.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, '<img src=\'img.gif\'
alt=\'abcde...\'/>');
}
function testTwoAttributeDoubleQuoteVar() {
$Template = '<img src="img.gif"
alt="{$val|clip:5,0,"..."}" title="{$val|clip:5,0,"..."}"/>';
RegisterTestingTemplate('/template/filter/testtwoattributedoublequote.html',
$Template);
$Page =& new
Template('/template/filter/testtwoattributedoublequote.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, '<img src="img.gif"
alt="abcde..." title="abcde..."/>');
}
/*
// THIS TEST WILL CAUSE A TIMEOUT ERROR
function testTwoAttributeSingleQuoteVar() {
$Template = '<img src=\'img.gif\'
alt=\'{'.'$val|clip:5,0,\'...\'}\'
title=\'{'.'$val|clip:5,0,\'...\'}\'/>';
RegisterTestingTemplate('/template/filter/testtwoattributesinglequote.html',
$Template);
$Page =& new
Template('/template/filter/testtwoattributesinglequote.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, "<img src='img.gif'
alt='abcde...' title='abcde...'/>");
}
*/
function testTwoAttributeMixedQuote1Var() {
$Template = '<img src="img.gif"
alt="{$val|clip:5,0,\'...\'}"
title="{$val|clip:5,0,\'...\'}"/>';
RegisterTestingTemplate('/template/filter/testtwoattributemixedquote1.html',
$Template);
$Page =& new
Template('/template/filter/testtwoattributemixedquote1.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, '<img src="img.gif"
alt="abcde..." title="abcde..."/>');
}
function testTwoAttributeMixedQuote2Var() {
$Template = '<img src=\'img.gif\'
alt=\'{'.'$val|clip:5,0,"..."}\'
title=\''.'{$val|clip:5,0,"..."}\'/>';
RegisterTestingTemplate('/template/filter/testtwoattributemixedquote2.html',
$Template);
$Page =& new
Template('/template/filter/testtwoattributemixedquote2.html');
$Page->Set('val','abcdefgh');
$output = $Page->capture();
$this->assertEqual($output, '<img src=\'img.gif\'
alt=\'abcde...\' title=\'abcde...\'/>');
}
}
?>
Logged In: YES
user_id=569780
OK - seems those tests fail the same way both on the earlier
versions of expressionparser.inc.php and expression.inc.php
(before Lexer) and with the new version.
With the new version, ExpressionValueParser is somehow
failing to pick up string constants as arguments.
Guess we could either fix it or (seems to me) make our lives
alot easier with a different syntax for string constants.
Note XML_HTMLSax is _not_ tripped by quotes / apostrophies
in attributes so long as they are not the same as the
attributes themselves eg.
<tag attr="foo 'bar' foo"> works
<tag attr='foo "bar" foo'> works
<tag attr="foo "bar" foo"> doesnt
<tag attr='foo 'bar' foo'> doesnt
Logged In: YES
user_id=569780
Moving this to bugs. See the failing clipfilter tests.