summaryrefslogtreecommitdiff
path: root/dist/Data-Dumper/Dumper.xs
diff options
context:
space:
mode:
authorAaron Crane <arc@cpan.org>2018-04-21 16:59:46 +0200
committerAaron Crane <arc@cpan.org>2018-07-22 13:39:12 +0100
commit00ec40a9bf1e535ebdff5b68456e4a06aa171211 (patch)
tree97e3ba10ccdf78c6815a124bf4865aaa406b9da5 /dist/Data-Dumper/Dumper.xs
parent4dbf3121c58281f425531759068eef60b39f7a9d (diff)
downloadperl-00ec40a9bf1e535ebdff5b68456e4a06aa171211.tar.gz
Data::Dumper: handle incomplete support for Unicode glob names
Before version 5.16, Perl didn't have full support for Unicode in glob names. This change allows Data::Dumper's tests to pass in Perl 5.8 through 5.14.
Diffstat (limited to 'dist/Data-Dumper/Dumper.xs')
-rw-r--r--dist/Data-Dumper/Dumper.xs23
1 files changed, 20 insertions, 3 deletions
diff --git a/dist/Data-Dumper/Dumper.xs b/dist/Data-Dumper/Dumper.xs
index 1709451a9a..95571913ea 100644
--- a/dist/Data-Dumper/Dumper.xs
+++ b/dist/Data-Dumper/Dumper.xs
@@ -89,6 +89,7 @@ static STRLEN num_q (const char *s, STRLEN slen);
static STRLEN esc_q (char *dest, const char *src, STRLEN slen);
static STRLEN esc_q_utf8 (pTHX_ SV *sv, const char *src, STRLEN slen, I32 do_utf8, I32 useqq);
static bool globname_needs_quote(const char *s, STRLEN len);
+static bool globname_supra_ascii(const char *s, STRLEN len);
static bool key_needs_quote(const char *s, STRLEN len);
static bool safe_decimal_number(const char *p, STRLEN len);
static SV *sv_x (pTHX_ SV *sv, const char *str, STRLEN len, I32 n);
@@ -182,6 +183,22 @@ TOP:
return FALSE;
}
+#ifndef GvNAMEUTF8
+/* does a glob name contain supra-ASCII characters? */
+static bool
+globname_supra_ascii(const char *ss, STRLEN len)
+{
+ const U8 *s = (const U8 *) ss;
+ const U8 *send = s+len;
+ while (s < send) {
+ if (!isASCII(*s))
+ return TRUE;
+ s++;
+ }
+ return FALSE;
+}
+#endif
+
/* does a hash key need to be quoted (to the left of => ).
Previously this used (globname_)needs_quote() which accepted strings
like '::foo', but these aren't safe as unquoted keys under strict.
@@ -1322,11 +1339,11 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
SvCUR_set(retval, SvCUR(retval)+2);
i = 3 + esc_q_utf8(aTHX_ retval, c, i,
#ifdef GvNAMEUTF8
- !!GvNAMEUTF8(val)
+ !!GvNAMEUTF8(val), style->useqq
#else
- 0
+ 0, style->useqq || globname_supra_ascii(c, i)
#endif
- , style->useqq);
+ );
sv_grow(retval, SvCUR(retval)+2);
r = SvPVX(retval)+SvCUR(retval);
r[0] = '}'; r[1] = '\0';