Skip to content

Commit e929c00

Browse files
committed
fixup correct handling of non-ASCII parameter names
1 parent 25688cd commit e929c00

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

pp.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7995,8 +7995,9 @@ PP(pp_multiparam)
79957995
val = svp ? *svp : &PL_sv_undef;
79967996
}
79977997

7998+
/* namepv / namelen are always UTF-8 */
79987999
STRLEN namelen;
7999-
const char *namepv = SvPV(name, namelen);
8000+
const char *namepv = SvPVutf8(name, namelen);
80008001

80018002
U32 namehash;
80028003
PERL_HASH(namehash, namepv, namelen);
@@ -8059,8 +8060,8 @@ PP(pp_multiparam)
80598060
else {
80608061
// TODO: Consider collecting up all the names of unrecognised
80618062
// in one string
8062-
croak_caller("Unrecognized named parameter '%s' to subroutine '%" SVf "'",
8063-
namepv, S_find_runcv_name());
8063+
croak_caller("Unrecognized named parameter '%" UTF8f "' to subroutine '%" SVf "'",
8064+
UTF8fARG(true, namelen, namepv), S_find_runcv_name());
80648065
}
80658066
}
80668067

@@ -8071,8 +8072,8 @@ PP(pp_multiparam)
80718072

80728073
// TODO: Consider collecting up all the names of missing
80738074
// parameters in one string
8074-
croak_caller("Missing required named parameter '%s' to subroutine '%" SVf "'",
8075-
named->namepv, S_find_runcv_name());
8075+
croak_caller("Missing required named parameter '%" UTF8f "' to subroutine '%" SVf "'",
8076+
UTF8fARG(true, named->namelen, named->namepv), S_find_runcv_name());
80768077
}
80778078
}
80788079

t/op/signatures.t

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,30 @@ sub tnamed07 (:$x, :$y, %) { "x=$x y=$y"; }
965965
is prototype(\&tnamed07), undef;
966966
is eval("tnamed07(w => 'W', x => 'X', y => 'Y', z => 'Z')"), "x=X y=Y";
967967

968+
# Unicode handling of parameter names
969+
{
970+
use utf8;
971+
972+
sub tnamed08 (:$ĉevaloj) { return "$ĉevaloj horses"; }
973+
974+
is eval("tnamed08(ĉevaloj => 1)"), "1 horses";
975+
976+
is eval("tnamed08()"), undef;
977+
like $@, qr/^Missing required named parameter 'ĉevaloj' to subroutine 'main::tnamed08' at /;
978+
979+
is eval("tnamed08(ŝafoj => 5)"), undef;
980+
like $@, qr/^Unrecognized named parameter 'ŝafoj' to subroutine 'main::tnamed08' at /;
981+
}
982+
983+
# Handling of Unicode parameter names from non-utf8 contexts
984+
{
985+
use utf8;
986+
987+
sub tnamed09 (:$café) { return $café; }
988+
}
989+
# "café" = "caf\x{e9}"
990+
is eval('tnamed09("caf\x{e9}", "Ritz")'), "Ritz";
991+
968992
sub t085
969993
(
970994
$

0 commit comments

Comments
 (0)