This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Unicode::UCD::prop_value_aliases() Don't return invalid value
authorKarl Williamson <khw@cpan.org>
Wed, 18 Feb 2015 18:57:02 +0000 (11:57 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 18 Feb 2015 19:51:34 +0000 (12:51 -0700)
Prior to this commit, if you said

    prop_value_aliases("Any", "foo")

it would return "foo".  But there really aren't any synonyms for the
"Any" property values, so it should return undef instead.

charclass_invlists.h
lib/Unicode/UCD.pm
lib/Unicode/UCD.t
pod/perldelta.pod

index 0135c7f..e3f0099 100644 (file)
@@ -50101,7 +50101,7 @@ static const UV XPosixXDigit_invlist[] = { /* for EBCDIC POSIX-BC */
 #endif /* EBCDIC POSIX-BC */
 
 /* Generated from:
- * 522e6488a0de8931f0ae95d4841471102ffa35f42217d4864570e2a8f70aa6c1 lib/Unicode/UCD.pm
+ * 56a23229a7896d5edf8fc138694f73fedc006c544ef3f8bf28afe5c2426bb7dc lib/Unicode/UCD.pm
  * 827aa7ee45ca9fe09f3e0969a5a27a69ce58a6c7134548125266210018d27b49 lib/unicore/ArabicShaping.txt
  * 3748fbbe9d280a9da700bfd0c28beaaf6f32a67ec263a124fcb0a4095a30fae5 lib/unicore/BidiBrackets.txt
  * 3925329c2432fa7248b2e180cddcedb9a4f9eafbbb10ab9e105eaf833043b2fb lib/unicore/BidiMirroring.txt
index 5d3115d..da2e1c3 100644 (file)
@@ -2130,7 +2130,18 @@ sub prop_value_aliases ($$) {
     # anything, like most (if not all) string properties.  These don't have
     # synonyms anyway.  Simply return the input.  For example, there is no
     # synonym for ('Uppercase_Mapping', A').
-    return $value if ! exists $prop_value_aliases{$prop};
+    if (! exists $prop_value_aliases{$prop}) {
+
+        # Here, we have a legal property, but an unknown value.  Since the
+        # property is legal, if it isn't in the prop_aliases hash, it must be
+        # a Perl-extension All perl extensions are binary, hence are
+        # enumerateds, which means that we know that the input unknown value
+        # is illegal.
+        return if ! exists $Unicode::UCD::prop_aliases{$prop};
+
+        # Otherwise, we assume it's valid, as documented.
+        return $value;
+    }
 
     # The value name may be loosely or strictly matched; we don't know yet.
     # But both types use lower-case.
index e54c5ee..419c338 100644 (file)
@@ -727,6 +727,8 @@ is(prop_value_aliases(undef, undef), undef,
 is((prop_value_aliases("na", "A")), "A", "test that prop_value_aliases returns its input for properties that don't have synonyms");
 is(prop_value_aliases("isgc", "C"), undef, "prop_value_aliases('isgc', 'C') returns <undef> since is not covered Perl extension");
 is(prop_value_aliases("gc", "isC"), undef, "prop_value_aliases('gc', 'isC') returns <undef> since is not covered Perl extension");
+is(prop_value_aliases("Any", "None"), undef, "prop_value_aliases('Any', 'None') returns <undef> since is Perl extension and 'None' is not valid");
+is(prop_value_aliases("lc", "A"), "A", "prop_value_aliases('lc', 'A') returns its input, as docs say it does");
 
 # We have no way of knowing if mktables omitted a Perl extension that it
 # shouldn't have, but we can check if it omitted an official Unicode property
index c968f91..673b813 100644 (file)
@@ -196,6 +196,13 @@ it was incorrect.
 
 =item *
 
+A bug has been fixed so that
+L<prop_value_aliases()|Unicode::UCD/prop_value_aliases()>
+returns C<undef> instead of a wrong result for properties that are Perl
+extensions.
+
+=item *
+
 This module now works on EBCDIC platforms.
 
 =back