improved tpl-resisting and testing

This commit is contained in:
Vadim A. Misbakh-Soloviov 2019-06-09 20:03:56 +03:00
parent 6f45c76030
commit b5362e0e55
No known key found for this signature in database
GPG Key ID: 6765F46F28E9607E
4 changed files with 44 additions and 44 deletions

View File

@ -4,12 +4,13 @@ sudo: false
env: env:
global: global:
- LUAROCKS=2.3.0 - LUAROCKS=3.1.3
matrix: matrix:
- LUA=lua5.1 - LUA=lua5.1
- LUA=lua5.2 - LUA=lua5.2
- LUA=lua5.3 - LUA=lua5.3
- LUA=luajit # latest stable version (2.0.4) - LUA=lua5.4
- LUA=luajit # latest stable version
- LUA=luajit2.0 # current head of 2.0 branch - LUA=luajit2.0 # current head of 2.0 branch
- LUA=luajit2.1 # current head of 2.1 branch - LUA=luajit2.1 # current head of 2.1 branch

View File

@ -2,13 +2,13 @@
# A script for setting up environment for travis-ci testing. # A script for setting up environment for travis-ci testing.
# Sets up Lua and Luarocks. # Sets up Lua and Luarocks.
# LUA must be "lua5.1", "lua5.2" or "luajit". # LUA must be "lua5.x" or "luajit".
# luajit2.0 - master v2.0 # luajit2.0 - master v2.0
# luajit2.1 - master v2.1 # luajit2.1 - master v2.1
set -eufo pipefail set -eufo pipefail
LUAJIT_VERSION="2.0.4" LUAJIT_VERSION="2.0.5"
LUAJIT_BASE="LuaJIT-$LUAJIT_VERSION" LUAJIT_BASE="LuaJIT-$LUAJIT_VERSION"
source .travis/platform.sh source .travis/platform.sh
@ -62,14 +62,14 @@ else
if [ "$LUA" == "lua5.1" ]; then if [ "$LUA" == "lua5.1" ]; then
curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz
cd lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then elif [ "$LUA" == "lua5.2" ]; then
curl http://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xz curl http://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xz
cd lua-5.2.4;
elif [ "$LUA" == "lua5.3" ]; then elif [ "$LUA" == "lua5.3" ]; then
curl http://www.lua.org/ftp/lua-5.3.2.tar.gz | tar xz curl http://www.lua.org/ftp/lua-5.3.5.tar.gz | tar xz
cd lua-5.3.2; elif [ "$LUA" == "lua5.4" ]; then
curl http://www.lua.org/work/lua-5.4.0-alpha-rc2.tar.gz | tar xz
fi fi
cd lua-5*
# Build Lua without backwards compatibility for testing # Build Lua without backwards compatibility for testing
perl -i -pe 's/-DLUA_COMPAT_(ALL|5_2)//' src/Makefile perl -i -pe 's/-DLUA_COMPAT_(ALL|5_2)//' src/Makefile

View File

@ -109,40 +109,36 @@ local function parse(text,limit) -- {{{
end end
-- g }}} -- g }}}
-- templaters {{{ -- tpl-placeholders and attributes {{{
text=text:gsub( text=text
[=[(=[%s]-)(['"])]=].. -- only match attr.values, and not random strings between two random quoting marks :gsub(
[=[([^%2<>]+)]=].. "(=[%s]-)".. -- only match attr.values, and not random strings between two random apostrophs
[=[([^%2>]-)]=].. "(%b'')",
[=[(%2)]=], function(...)return g(2,...)end
function(...)return g(4,...)end )
) -- Escape "<" inside attr.values (see issue #50) :gsub(
text=text:gsub( "(=[%s]-)".. -- same for "
[=[(=[%s]-)(['"])]=].. -- only match attr.values, and not random strings between two random quoting marks '(%b"")',
[=[([^%2<>]+)]=].. function(...)return g(2,...)end
[=[([^%2<]-)]=].. ) -- Escape "<"/">" inside attr.values (see issue #50)
[=[(%2)]=], :gsub(
function(...)return g(4,...)end "(<".. -- Match "<",
) -- Escape ">" inside attr.values (see issue #50) (opts.tpl_skip_pattern or "[^!]").. -- with exclusion pattern (for example, to ignore comments, which aren't template placeholders, but can legally contain "<"/">" inside.
--[[ ")([^>]+)".. -- If matched, we want to escape '<'s if we meet them inside tag
]]
text = text:gsub(
"(<[^!])".. -- Comments aren't templaters placeholders
"([^>]-)"..
"(>)", "(>)",
function(...)return g(2,...)end function(...)return g(2,...)end
) -- scan for a second "<", inside "<>" (if it shows before ">"), until it inside the comment or CDATA )
text=text:gsub( :gsub(
"("..tpr["<"]..")".. "("..
"([^%w%s])".. (tpr["<"] or "__FAILED__").. -- Here we search for "<", we escaped in previous gsub (and don't break things if we have no escaping replacement)
"([^%2]-)".. ")("..
"(%2)".. (opts.tpl_marker_pattern or "[^%w%s]").. -- Capture templating symbol
"(>)".. ")([%g%s]-)".. -- match placeholder's content
"([^>]-)".. "(%2)(>)".. -- placeholder's tail
"(>)", -- Comments and CDATA aren't templaters placeholders "([^>]*>)", -- remainings
function(...)return g(5,...)end function(...)return g(5,...)end
) -- try to find matching ">" for previous replace )
-- templaters }}} -- }}}
end -- }}} end -- }}}
local index = 0 local index = 0

View File

@ -309,8 +309,13 @@ end
function test_loop_limit() function test_loop_limit()
local tree = htmlparser.parse([[ local tree = htmlparser.parse([[
<a id='a >b'>moo</a>
<a id='c> d'>moo</a>
<a id='e > f'>moo</a>
<a id="g >h">moo</a>
<a id="i> j">moo</a>
<a id="k > l">moo</a>
<a id='1>2'>moo</a> <a id='1>2'>moo</a>
<a id='2>3'>moo</a>
<b id='foo<bar'>moo</b> <b id='foo<bar'>moo</b>
<img <%tpl%> foo=bar></img> <img <%tpl%> foo=bar></img>
<img <%tpl%> /> <img <%tpl%> />
@ -319,10 +324,8 @@ function test_loop_limit()
<i <=moo=>>k</i> <i <=moo=>>k</i>
<s <-foo->>o</s> <s <-foo->>o</s>
<div <*bar*>></div> <div <*bar*>></div>
<p>
<a id="unclosed>Element"> with unclosed attribute</a> <a id="unclosed>Element"> with unclosed attribute</a>
</p>
<div data-pic="aa<%=image_url%>bb" ></div> <div data-pic="aa<%=image_url%>bb" ></div>
]]) -- issue#42 ]]) -- issue#42
assert(1==1) assert(#tree.nodes==17)
end end