File: KinoSearch1-1.01-Do-not-use-C-in-regexps.patch

package info (click to toggle)
libkinosearch1-perl 1.01-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,568 kB
  • sloc: perl: 6,805; java: 168; makefile: 3
file content (78 lines) | stat: -rw-r--r-- 2,734 bytes parent folder | download | duplicates (3)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From 90b55f6267fa139df653147a106c8a58925fd451 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 19 May 2016 17:02:21 +0200
Subject: [PATCH] Do not use \C in regexps
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Pelr 5.24.0 removed support for \C (bytes positions). This patch
rewrites the tests for the ungreedy sequence of bytes with a miximum
size.

CPAN RT#105144

Signed-off-by: Petr Písař <ppisar@redhat.com>

Bug: https://rt.cpan.org/Public/Bug/Display.html?id=105144
Bug-Debian: https://bugs.debian.org/825233

---
 lib/KinoSearch1/Highlight/Highlighter.pm | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/lib/KinoSearch1/Highlight/Highlighter.pm b/lib/KinoSearch1/Highlight/Highlighter.pm
index bb8f910..50faca7 100644
--- a/lib/KinoSearch1/Highlight/Highlighter.pm
+++ b/lib/KinoSearch1/Highlight/Highlighter.pm
@@ -84,32 +84,39 @@ sub generate_excerpt {
         $text = bytes::substr( $text, $top );
 
         # try to start the excerpt at a sentence boundary
-        if ($text =~ s/
+        if ($text =~ /
                 \A
                 (
-                \C{0,$limit}?
+                (.*?)
                 \.\s+
                 )
-                //xsm
+                /xsm
+            and bytes::length($2) <= $limit
             )
         {
-            $top += bytes::length($1);
+            my $bytes_length = bytes::length($1);
+            $text = bytes::substr($text, $bytes_length);
+            $top += $bytes_length;
         }
         # no sentence boundary, so we'll need an ellipsis
         else {
             # skip past possible partial tokens, prepend an ellipsis
-            if ($text =~ s/
+            if ($text =~ /
                 \A
                 (
-                \C{0,$limit}?  # don't go outside the window
+                (.*?)          # don't go outside the window
                 $token_re      # match possible partial token
                 .*?            # ... and any junk following that token
                 )
                 (?=$token_re)  # just before the start of a full token...
-                /... /xsm    # ... insert an ellipsis
+                /xsm
+                and bytes::length($2) <= $limit # don't go outside the window
                 )
             {
-                $top += bytes::length($1);
+                my $bytes_length = bytes::length($1);
+                # ... insert an ellipsis
+                $text = '... ' . bytes::substr($text, $bytes_length);
+                $top += $bytes_length;
                 $top -= 4    # three dots and a space
             }
         }
-- 
2.5.5