Page MenuHomePhabricator

Pure-Lua ustring doesn't always report errors
Open, LowPublic


The following three function calls correctly return an error that the pattern has an unclosed capture:

require('ustring').find('abcdefghi', '(abc)(def)(ghi')
mw.ustring.find('abcdefghi', '(abc)(def)(ghi')
mw.ustring.find('abcdefgh', '(abc)(def)(ghi')

However, the following one gives no error and instead just returns nil:

require('ustring').find('abcdefgh', '(abc)(def)(ghi')

It should return the same error as the other three.

Event Timeline

Jackmcbarn raised the priority of this task from to Low.
Jackmcbarn updated the task description. (Show Details)
Jackmcbarn added a subscriber: Jackmcbarn.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJan 3 2016, 8:41 PM
Anomie added a subscriber: Anomie.Jan 4 2016, 6:47 AM

Note that Lua's string library behaves the same was as the pure-Lua ustring: both parse the pattern as needed while processing the match, so if it never gets to that part of the pattern it won't notice the error. The PHP mw.ustring, on the other hand, converts the Lua pattern into a PCRE regex and in the process winds up syntax-checking the whole pattern.

To make the pure-Lua ustring raise these errors, you'd have to rework things to have a "validate" function to run the pattern through.