1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
From: Enrico Tassi <gares@fettunta.org>
Date: Thu, 19 Sep 2013 16:49:54 +0200
Subject: Fix: loop body may accept empty string
Courtesy of Roberto Ierusalimschy on lua-l@lists.lua.org
Message-ID: <20130918201448.GA18049@inf.puc-rio.br>
---
src/cosmo/grammar.lua | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/cosmo/grammar.lua b/src/cosmo/grammar.lua
index a2490a0..97f9899 100644
--- a/src/cosmo/grammar.lua
+++ b/src/cosmo/grammar.lua
@@ -37,12 +37,10 @@ local longstring1 = lpeg.P{
longstring = lpeg.P"[[" * (lpeg.V"longstring" + (lpeg.P(1) - lpeg.P"]]"))^0 * lpeg.P"]]"
}
-local longstring2 = lpeg.P(function (s, i)
- local l = lpeg.match(start, s, i)
- if not l then return nil end
- local p = lpeg.P("]" .. string.rep("=", l - i - 2) .. "]")
- p = (1 - p)^0 * p
- return lpeg.match(p, s, l)
+local longstring2 = lpeg.Cmt(start, function (s, i, start)
+ local p = string.gsub(start, "%[", "]")
+ local _, e = string.find(s, p, i)
+ return (e and e + 1)
end)
local longstring = #("[" * lpeg.S"[=") * (longstring1 + longstring2)
|