diff --git a/.travis.yml b/.travis.yml
index 2d151f9..6f46178 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,12 +4,13 @@ sudo: false
env:
global:
- - LUAROCKS=2.3.0
+ - LUAROCKS=3.1.3
matrix:
- LUA=lua5.1
- LUA=lua5.2
- 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.1 # current head of 2.1 branch
diff --git a/.travis/setup_lua.sh b/.travis/setup_lua.sh
index 6dcc0c6..a6c31a6 100644
--- a/.travis/setup_lua.sh
+++ b/.travis/setup_lua.sh
@@ -2,13 +2,13 @@
# A script for setting up environment for travis-ci testing.
# 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.1 - master v2.1
set -eufo pipefail
-LUAJIT_VERSION="2.0.4"
+LUAJIT_VERSION="2.0.5"
LUAJIT_BASE="LuaJIT-$LUAJIT_VERSION"
source .travis/platform.sh
@@ -62,14 +62,14 @@ else
if [ "$LUA" == "lua5.1" ]; then
curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz
- cd lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then
curl http://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xz
- cd lua-5.2.4;
elif [ "$LUA" == "lua5.3" ]; then
- curl http://www.lua.org/ftp/lua-5.3.2.tar.gz | tar xz
- cd lua-5.3.2;
+ curl http://www.lua.org/ftp/lua-5.3.5.tar.gz | tar xz
+ elif [ "$LUA" == "lua5.4" ]; then
+ curl http://www.lua.org/work/lua-5.4.0-alpha-rc2.tar.gz | tar xz
fi
+ cd lua-5*
# Build Lua without backwards compatibility for testing
perl -i -pe 's/-DLUA_COMPAT_(ALL|5_2)//' src/Makefile
diff --git a/src/htmlparser.lua b/src/htmlparser.lua
index c43cd6b..19b7dec 100644
--- a/src/htmlparser.lua
+++ b/src/htmlparser.lua
@@ -109,40 +109,36 @@ local function parse(text,limit) -- {{{
end
-- g }}}
- -- templaters {{{
- text=text:gsub(
- [=[(=[%s]-)(['"])]=].. -- only match attr.values, and not random strings between two random quoting marks
- [=[([^%2<>]+)]=]..
- [=[([^%2>]-)]=]..
- [=[(%2)]=],
- function(...)return g(4,...)end
- ) -- Escape "<" inside attr.values (see issue #50)
- text=text:gsub(
- [=[(=[%s]-)(['"])]=].. -- only match attr.values, and not random strings between two random quoting marks
- [=[([^%2<>]+)]=]..
- [=[([^%2<]-)]=]..
- [=[(%2)]=],
- function(...)return g(4,...)end
- ) -- Escape ">" inside attr.values (see issue #50)
---[[
-]]
- text = text:gsub(
- "(<[^!])".. -- Comments aren't templaters placeholders
- "([^>]-)"..
+ -- tpl-placeholders and attributes {{{
+ text=text
+ :gsub(
+ "(=[%s]-)".. -- only match attr.values, and not random strings between two random apostrophs
+ "(%b'')",
+ function(...)return g(2,...)end
+ )
+ :gsub(
+ "(=[%s]-)".. -- same for "
+ '(%b"")',
+ function(...)return g(2,...)end
+ ) -- Escape "<"/">" inside attr.values (see issue #50)
+ :gsub(
+ "(<".. -- Match "<",
+ (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
"(>)",
function(...)return g(2,...)end
- ) -- scan for a second "<", inside "<>" (if it shows before ">"), until it inside the comment or CDATA
- text=text:gsub(
- "("..tpr["<"]..")"..
- "([^%w%s])"..
- "([^%2]-)"..
- "(%2)"..
- "(>)"..
- "([^>]-)"..
- "(>)", -- Comments and CDATA aren't templaters placeholders
+ )
+ :gsub(
+ "("..
+ (tpr["<"] or "__FAILED__").. -- Here we search for "<", we escaped in previous gsub (and don't break things if we have no escaping replacement)
+ ")("..
+ (opts.tpl_marker_pattern or "[^%w%s]").. -- Capture templating symbol
+ ")([%g%s]-)".. -- match placeholder's content
+ "(%2)(>)".. -- placeholder's tail
+ "([^>]*>)", -- remainings
function(...)return g(5,...)end
- ) -- try to find matching ">" for previous replace
- -- templaters }}}
+ )
+ -- }}}
end -- }}}
local index = 0
diff --git a/tst/init.lua b/tst/init.lua
index 3ea7ae2..eb1bbf6 100644
--- a/tst/init.lua
+++ b/tst/init.lua
@@ -309,8 +309,13 @@ end
function test_loop_limit()
local tree = htmlparser.parse([[
+ moo
+ moo
+ moo
+ moo
+ moo
+ moo
moo
- moo
moo
foo=bar>
/>
@@ -319,10 +324,8 @@ function test_loop_limit()
>k
>o