File: 0001-Fix-splitting-the-empty-string.patch

package info (click to toggle)
ocaml-re 1.13.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 776 kB
  • sloc: ml: 6,455; makefile: 18; sh: 11
file content (36 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download
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
32
33
34
35
36
From: Stephane Glondu <steph@glondu.net>
Date: Tue, 26 Aug 2025 10:45:52 +0200
Subject: Fix splitting the empty string

Bug: https://github.com/ocaml/ocaml-re/issues/584
---
 lib/pcre.ml                      | 2 +-
 lib_test/expect/test_pcre_288.ml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/pcre.ml b/lib/pcre.ml
index 6287594..1772aca 100644
--- a/lib/pcre.ml
+++ b/lib/pcre.ml
@@ -112,7 +112,7 @@ let split ~rex str =
         else loop accu fin fin true))
     else finish str last accu
   in
-  loop [] 0 0 false
+  if str = "" then [] else loop [] 0 0 false
 ;;
 
 (* From PCRE *)
diff --git a/lib_test/expect/test_pcre_288.ml b/lib_test/expect/test_pcre_288.ml
index 30ae0d4..a6d08ee 100644
--- a/lib_test/expect/test_pcre_288.ml
+++ b/lib_test/expect/test_pcre_288.ml
@@ -5,7 +5,7 @@ let whitespace_re = Pcre.regexp "\\s+"
 
 let%expect_test "split1" =
   strings (Pcre.split ~rex:whitespace_re "");
-  [%expect {| [""] |}]
+  [%expect {| [] |}]
 ;;
 
 let%expect_test "split2" =