Hello hackers,
here's a patch for the bug reported by Chunyang Xu on CHICKEN-users, I'm
reporting a piece of their mail below:

>  #;1> (use utf8)
>  ; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/utf8.import.so ...
>  ; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/utf8.so ...
>  #;5> (string-match "[一二]" "三四")
>  
>  Error: (sre-length-ranges) unknown sre: ()
>  
>        Call history:
>  
>        <syntax>          (string-match "[一二]" "三四")
>        <eval>    (string-match "[一二]" "三四")    <--
>  #;14> 

The fix is really simple but a bit hairy IMO, feel free to refactor the code,
and simply avoids the tailing '() by stopping before the end of the list is
reached.

Another approach that results in a slightly longer patch is to generate a single
`sre-sequence' with a tail-recursive loop, if you prefer this kind of fix you
just have to ask :)

Oh, the patch is made against the chicken-5 branch, backporting it to master
should be straightforward.

Cheers,
LemonBoy
>From c80002f2d8de8e4c06636e2b11a8fd2adafc49f1 Mon Sep 17 00:00:00 2001
From: LemonBoy <[email protected]>
Date: Thu, 9 Nov 2017 13:29:08 +0100
Subject: [PATCH] Fix an error in unicode-range->utf8-pattern

The sequence generated for a utf8 character class contained an
unintended trailing '(), causing the code to fail when
`sre-length-ranges' is called.

Reported by Chunyang Xu at CHICKEN-users.
---
 irregex-core.scm       | 7 +++----
 tests/test-irregex.scm | 2 ++
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/irregex-core.scm b/irregex-core.scm
index c83aff9b..bef8336e 100644
--- a/irregex-core.scm
+++ b/irregex-core.scm
@@ -1402,12 +1402,11 @@
                              (unicode-range-up-to hi-ls)))
         (let lp ((lo-ls lo-ls) (hi-ls hi-ls))
           (cond
-           ((null? lo-ls)
-            '())
            ((= (car lo-ls) (car hi-ls))
             (sre-sequence
-             (list (integer->char (car lo-ls))
-                   (lp (cdr lo-ls) (cdr hi-ls)))))
+             (cons (integer->char (car lo-ls))
+                   (if (null? (cdr lo-ls)) '()
+                       (cons (lp (cdr lo-ls) (cdr hi-ls)) '())))))
            ((= (+ (car lo-ls) 1) (car hi-ls))
             (sre-alternate (list (unicode-range-up-from lo-ls)
                                  (unicode-range-up-to hi-ls))))
diff --git a/tests/test-irregex.scm b/tests/test-irregex.scm
index 19218bd8..d7bfaf59 100644
--- a/tests/test-irregex.scm
+++ b/tests/test-irregex.scm
@@ -539,6 +539,8 @@
 (test-assert (not (irregex-search "(?u:<[^あ-ん語]*>)" "<ひらがな>")))
 (test-assert (not (irregex-search "(?u:<[^あ-ん語]*>)" "<語>")))
 
+(test-assert (not (irregex-search (irregex "[一二]" 'utf8 #t) "三四")))
+
 (test-end)
 
 (test-exit)
-- 
2.11.0

_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to