b8c914
From dc5c68130b7c8b727e9e792506183c255fc2bc70 Mon Sep 17 00:00:00 2001
b8c914
From: Tony Cook <tony@develop-help.com>
b8c914
Date: Thu, 19 Oct 2017 10:46:04 +1100
b8c914
Subject: [PATCH] (perl #132245) don't try to process a char range with no
b8c914
 preceding char
b8c914
MIME-Version: 1.0
b8c914
Content-Type: text/plain; charset=UTF-8
b8c914
Content-Transfer-Encoding: 8bit
b8c914
b8c914
A range like \N{}-0 eventually results in compilation failing, but
b8c914
before that, get_and_check_backslash_N_name() attempts to treat
b8c914
the memory before the empty output of \N{} as a character.
b8c914
b8c914
Petr Písař: Ported to 5.26.1.
b8c914
b8c914
Signed-off-by: Petr Písař <ppisar@redhat.com>
b8c914
---
b8c914
 t/lib/warnings/toke | 5 +++++
b8c914
 toke.c              | 6 +++---
b8c914
 2 files changed, 8 insertions(+), 3 deletions(-)
b8c914
b8c914
diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke
b8c914
index fc51d9f..398ee22 100644
b8c914
--- a/t/lib/warnings/toke
b8c914
+++ b/t/lib/warnings/toke
b8c914
@@ -1651,3 +1651,8 @@ Execution of - aborted due to compilation errors.
b8c914
 use utf8;
b8c914
 qw∘foo ∞ ♥ bar∘
b8c914
 EXPECT
b8c914
+########
b8c914
+# NAME tr/// range with empty \N{} at the start
b8c914
+tr//\N{}-0/;
b8c914
+EXPECT
b8c914
+Unknown charname '' is deprecated. Its use will be fatal in Perl 5.28 at - line 1.
b8c914
diff --git a/toke.c b/toke.c
b8c914
index 6f84d2d..6ee7a68 100644
b8c914
--- a/toke.c
b8c914
+++ b/toke.c
b8c914
@@ -2958,9 +2958,9 @@ S_scan_const(pTHX_ char *start)
b8c914
 
b8c914
                 /* Here, we don't think we're in a range.  If the new character
b8c914
                  * is not a hyphen; or if it is a hyphen, but it's too close to
b8c914
-                 * either edge to indicate a range, then it's a regular
b8c914
-                 * character. */
b8c914
-                if (*s != '-' || s >= send - 1 || s == start) {
b8c914
+                 * either edge to indicate a range, or if we haven't output any
b8c914
+                 * characters yet then it's a regular character. */
b8c914
+                if (*s != '-' || s >= send - 1 || s == start || d == SvPVX(sv)) {
b8c914
 
b8c914
                     /* A regular character.  Process like any other, but first
b8c914
                      * clear any flags */
b8c914
-- 
b8c914
2.13.6
b8c914