question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with frontier patterns

See original GitHub issue

%f[set], a frontier pattern; such item matches an empty string at any position such that the next character belongs to set and the previous character does not belong to set. The set set is interpreted as previously described. The beginning and the end of the subject are handled as if they were the character ‘\0’.

– Lua 5.2 Reference Manual, §6.4.1

In the reference interpreter (Lua 5.3.4), the code belows prints a blank line and nil, indicating that the first pattern matched (‘o’ is not in [%.], but ‘.’ is) and that the second one didn’t.

In LuaJ 3.0.1, however, the code fails with

  org.luaj.vm2.LuaError: frontier-pattern-handling.lua:9 vm error: java.lang.ArrayIndexOutOfBoundsException: -1
  stack traceback:
    frontier-pattern-handling.lua:9: in main chunk
    [Java]: in ?
    at org.luaj.vm2.LuaClosure.execute(Unknown Source)
    at org.luaj.vm2.LuaClosure.onInvoke(Unknown Source)
    at org.luaj.vm2.LuaClosure.invoke(Unknown Source)
    at lua.processScript(Unknown Source)
    at lua.main(Unknown Source)
  Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
    at org.luaj.vm2.lib.StringLib$MatchState.match_class(Unknown Source)
    at org.luaj.vm2.lib.StringLib$MatchState.matchbracketclass(Unknown Source)
    at org.luaj.vm2.lib.StringLib$MatchState.match(Unknown Source)
    at org.luaj.vm2.lib.StringLib$MatchState.start_capture(Unknown Source)
    at org.luaj.vm2.lib.StringLib$MatchState.match(Unknown Source)
    at org.luaj.vm2.lib.StringLib.str_find_aux(Unknown Source)
    at org.luaj.vm2.lib.StringLib$match.invoke(Unknown Source)
print(string.match("foo.", "(%f[%.])"))
print(string.match("foo", "(%f[%.])"))

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
plamentotevcommented, Mar 3, 2018

I think I found where the issue is. Here is a patch:

--- StringLib.java      2018-03-03 23:06:25.584417500 +0200
+++ luaj-3.0.1/src/core/org/luaj/vm2/lib/StringLib.java 2018-03-03 23:06:53.158652400 +0200
@@ -1066,9 +1066,12 @@
                                                        error("Missing [ after %f in pattern");
                                                }
                                                int ep = classend( poffset );
-                                               int previous = ( soffset == 0 ) ? 0 : s.luaByte( soffset - 1 );
+                                               int previous = ( soffset == 0 ) ? '\0' : s.luaByte( soffset - 1 );
+                                               // The C version does not do this check
+                                               // because in C strings are '\0' terminated
+                                               int next = ( soffset == s.length() ) ? '\0' : s.luaByte( soffset );
                                                if ( matchbracketclass( previous, poffset, ep - 1 ) ||
-                                                        matchbracketclass( s.luaByte( soffset ), poffset, ep - 1 ) )
+                                                        !matchbracketclass( next, poffset, ep - 1 ) )
                                                        return -1;
                                                poffset = ep;
                                                continue;

I would create PR once #4 is resolved.

As for the commits. This could be easily fix once the source forge is back online. I’ve created new issue to track this better #5

0reactions
plamentotevcommented, Sep 16, 2018

@Enyby to be honest I forgot the details about this issue. I may take a look at it again but not sure if I would have time soon. Feel free to use the patch and create PR if you want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Frontier Pattern - lua-users wiki
The frontier pattern %f followed by a set detects the transition from "not in set" to "in set". The source string boundary qualifies...
Read more >
Patterns of frontier genocide 1803–1910: the Aboriginal ...
In the frontier genocide pattern, two political issues dominate an indigenous people's decision to go to war: the mistreatment of women and the...
Read more >
Dark Patterns | Frontier
Dark Patterns. Written By Tristan Marantos Illustrations by Anthony Gerace A version of this article appears in. Frontier Magazine Issue 03 / Darkness....
Read more >
Patterns of frontier genocide 1803–1910: the aboriginal ...
Volume 6, 2004 - Issue 2 ... Patterns of frontier genocide 1803–1910: the aboriginal Tasmanians, the Yuki of California, and the Herero of ......
Read more >
Pattern Curator Issue #2 Trend Report & Analysis
Highly anticipated, PatternCurator Issue #1 Trend Report & Analysis: FRONTIER includes an in-depth dynamic way of looking at one concept.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found