Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
Dwoo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Common
Dwoo
Commits
f377fd89
Commit
f377fd89
authored
May 17, 2008
by
Seldaek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* {literal} and {strip} now follow the LooseOpeningsHandling setting
git-svn-id:
svn://dwoo.org/dwoo/trunk@64
0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent
9749a55f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
7 deletions
+33
-7
CHANGELOG
CHANGELOG
+1
-0
Compiler.php
lib/Dwoo/Compiler.php
+12
-7
CompilerTests.php
tests/CompilerTests.php
+20
-0
No files found.
CHANGELOG
View file @
f377fd89
...
...
@@ -3,6 +3,7 @@
*
Optimized
scope
-
handling
functions
,
{
loop
}
and
{
with
}
are
now
slightly
faster
*
Fixed
a
bug
in
{
date_format
}
that
prevented
anything
but
unix
timestamps
to
work
*
{
literal
}
and
{
strip
}
now
follow
the
LooseOpeningsHandling
setting
[
2008
-
05
-
10
]
0.9.0
! BC Break: changed all class names to be PEAR compliant (aka use underscores
...
...
lib/Dwoo/Compiler.php
View file @
f377fd89
...
...
@@ -514,8 +514,12 @@ class Dwoo_Compiler implements Dwoo_ICompiler
}
// handles the built-in strip function
if
((
$pos
=
strpos
(
$tpl
,
$this
->
ld
.
'strip'
.
$this
->
rd
))
!==
false
&&
substr
(
$tpl
,
$pos
-
1
,
1
)
!==
'\\'
)
$tpl
=
preg_replace_callback
(
'{'
.
$this
->
ldr
.
'strip'
.
$this
->
rdr
.
'(.+?)'
.
$this
->
ldr
.
'/strip'
.
$this
->
rdr
.
'}s'
,
array
(
$this
,
'stripPreprocessorHelper'
),
$tpl
);
if
(
preg_match
(
'/'
.
$this
->
ldr
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
'strip'
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
$this
->
rdr
.
'/s'
,
$tpl
,
$pos
,
PREG_OFFSET_CAPTURE
)
&&
substr
(
$tpl
,
$pos
[
0
][
1
]
-
1
,
1
)
!==
'\\'
)
{
if
(
!
preg_match
(
'/'
.
$this
->
ldr
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
'\/strip'
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
$this
->
rdr
.
'/s'
,
$tpl
))
throw
new
Dwoo_Compilation_Exception
(
'The {strip} blocks must be closed explicitly'
);
$tpl
=
preg_replace_callback
(
'/'
.
$this
->
ldr
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
'strip'
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
$this
->
rdr
.
'(.+?)'
.
$this
->
ldr
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
'\/strip'
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
$this
->
rdr
.
'/s'
,
array
(
$this
,
'stripPreprocessorHelper'
),
$tpl
);
}
while
(
true
)
{
...
...
@@ -544,12 +548,13 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$compiled
.=
substr
(
$tpl
,
$ptr
,
$pos
-
$ptr
-
1
)
.
$this
->
ld
;
$ptr
=
$pos
+
strlen
(
$this
->
ld
);
}
elseif
(
strpos
(
$tpl
,
$this
->
ld
.
'literal'
.
$this
->
rd
,
$pos
)
===
$pos
)
elseif
(
preg_match
(
'/^'
.
$this
->
ldr
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
'literal'
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
$this
->
rdr
.
'/s'
,
substr
(
$tpl
,
$pos
),
$litOpen
)
)
{
$endpos
=
strpos
(
$tpl
,
$this
->
ld
.
'/literal'
.
$this
->
rd
,
$pos
);
$compiled
.=
substr
(
$tpl
,
$ptr
,
$pos
-
$ptr
);
$compiled
.=
substr
(
$tpl
,
$pos
+
strlen
(
$this
->
ld
.
'literal'
.
$this
->
rd
),
$endpos
-
$pos
-
strlen
(
$this
->
ld
.
'literal'
.
$this
->
rd
));
$ptr
=
$endpos
+
strlen
(
$this
->
ld
.
'/literal'
.
$this
->
rd
);
if
(
!
preg_match
(
'/'
.
$this
->
ldr
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
'\/literal'
.
(
$this
->
allowLooseOpenings
?
'\s*'
:
''
)
.
$this
->
rdr
.
'/s'
,
$tpl
,
$litClose
,
PREG_OFFSET_CAPTURE
,
$pos
))
throw
new
Dwoo_Compilation_Exception
(
'The {literal} blocks must be closed explicitly'
);
$endpos
=
$litClose
[
0
][
1
];
$compiled
.=
substr
(
$tpl
,
$ptr
,
$pos
-
$ptr
)
.
substr
(
$tpl
,
$pos
+
strlen
(
$litOpen
[
0
]),
$endpos
-
$pos
-
strlen
(
$litOpen
[
0
]));
$ptr
=
$endpos
+
strlen
(
$litClose
[
0
][
0
]);
}
else
{
...
...
tests/CompilerTests.php
View file @
f377fd89
...
...
@@ -140,6 +140,16 @@ class CompilerTests extends PHPUnit_Framework_TestCase
$this
->
assertEquals
(
"abca
\n
b
\n
c"
,
$this
->
dwoo
->
get
(
$tpl
,
array
(),
$this
->
compiler
));
}
/**
* @expectedException Dwoo_Compilation_Exception
*/
public
function
testUnclosedStrip
()
{
$tpl
=
new
Dwoo_Template_String
(
"
{
strip
}
a
\n
b
\n
ca
\n
b
\n
c"
);
$tpl
->
forceCompilation
();
$this
->
dwoo
->
get
(
$tpl
,
array
(),
$this
->
compiler
);
}
public
function
testWhitespace
()
{
$tpl
=
new
Dwoo_Template_String
(
"
{
\$foo}{\$foo}\n{\$foo}\n\n{\$foo}\n\n\n{\$foo
}
"
);
...
...
@@ -154,6 +164,16 @@ class CompilerTests extends PHPUnit_Framework_TestCase
$this
->
assertEquals
(
'{$foo}{hurray}'
,
$this
->
dwoo
->
get
(
$tpl
,
array
(),
$this
->
compiler
));
}
/**
* @expectedException Dwoo_Compilation_Exception
*/
public
function
testUnclosedLiteral
()
{
$tpl
=
new
Dwoo_Template_String
(
'{literal}{$foo}{hurray}'
);
$tpl
->
forceCompilation
();
$this
->
dwoo
->
get
(
$tpl
,
array
(),
$this
->
compiler
);
}
public
function
testEscaping
()
{
$tpl
=
new
Dwoo_Template_String
(
'\{foo\{bar\\\\{$var}}{"tes\}t"}{"foo\"lol\"bar"}'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment