From b6b27fd6b3d92ea62e660d857482759ab4fcffbe Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 25 Mar 2018 15:24:28 -0700 Subject: [PATCH] Qt-LGPL-exception-1.1: Order match from longest to shortest The alternation operator (|) is commutative in the POSIX spec, which has [1]: > If the pattern permits a variable number of matching characters and > thus there is more than one such sequence starting at that point, > the longest such sequence is matched. Testing with a few engines, here are some that match POSIX: $ echo abc | grep -Eo '|a|ab' ab $ python -c 'import regex; print(regex.match("|a|ab", "abc", regex.POSIX).group(0))' ab # Background in https://bitbucket.org/mrabarnett/mrab-regex/issues/150 $ psql -Atc "select substring('abc' from '|a|ab')" ab The docs for PostgreSQL are somewhat complicated, but for two or more branches connected by the | operator they are always greedy [2]. Here are some engines that prefer the left-most branch: $ python -c 'import re; print(re.match("|a|ab", "abc").group(0))' $ python -c 'import regex; print(regex.match("|a|ab", "abc").group(0))' $ node -e 'console.log("abc".match(/|a|ab/)[0])' # [3] $ ruby -e 'print "abc".match(/|a|ab/); print "\n"' # [4] Go's stdlib provides both left-most-branch [5] and longest-match [6] implementations. So the old order was compliant with POSIX EREs (as referenced in schema/ListedLicense.xsd), but this commit sorts the branches for longest-match-first for compatibility with engines that break POSIX and prefer the left-most branch. [1]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_01_02 [2]: https://www.postgresql.org/docs/10/static/functions-matching.html#POSIX-MATCHING-RULES [3]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-or [4]: https://ruby-doc.org/core-2.5.0/Regexp.html#class-Regexp-label-Alternation Although these docs don't have much to say on longest-match vs. left-most branch. [5]: https://golang.org/pkg/regexp/#Compile [6]: https://golang.org/pkg/regexp/#CompilePOSIX --- src/exceptions/Qt-LGPL-exception-1.1.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exceptions/Qt-LGPL-exception-1.1.xml b/src/exceptions/Qt-LGPL-exception-1.1.xml index ba0888715..290ebd51b 100644 --- a/src/exceptions/Qt-LGPL-exception-1.1.xml +++ b/src/exceptions/Qt-LGPL-exception-1.1.xml @@ -7,7 +7,7 @@ Used with the LGPL-2.1, which is mentioned explicitly in the exception text. -

The Qt Company Qt LGPL Exception version 1.1

+

The Qt Company Qt LGPL Exception version 1.1

As an additional permission to the GNU Lesser General Public License version 2.1, the object code form of a "work that