diff options
-rw-r--r-- | src/LDNS.xs | 24 | ||||
-rw-r--r-- | t/idn.t | 7 |
2 files changed, 18 insertions, 13 deletions
diff --git a/src/LDNS.xs b/src/LDNS.xs index 110285e..c3cef69 100644 --- a/src/LDNS.xs +++ b/src/LDNS.xs @@ -16,18 +16,21 @@ to_idn(...) int status; SV *obj = ST(i); - status = idna_to_ascii_8z(SvPV_nolen(obj), &out, IDNA_ALLOW_UNASSIGNED); - if (status == IDNA_SUCCESS) + if (SvPOK(ST(i))) { - SV *new = newSVpv(out,0); - SvUTF8_on(new); /* We know the string is plain ASCII, so let Perl know too */ - mXPUSHs(new); + status = idna_to_ascii_8z(SvPVutf8_nolen(obj), &out, IDNA_ALLOW_UNASSIGNED); + if (status == IDNA_SUCCESS) + { + SV *new = newSVpv(out,0); + SvUTF8_on(new); /* We know the string is plain ASCII, so let Perl know too */ + mXPUSHs(new); + free(out); + } + else + { + croak("Error: %s\n", idna_strerror(status)); + } } - else - { - croak("Error: %s\n", idna_strerror(status)); - } - free(out); } #else croak("libidn not installed"); @@ -2084,6 +2087,7 @@ rr_nsec3_covers(obj,name) ldns_rr2canonical(clone); hashed = ldns_nsec3_hash_name_frm_nsec3(clone, dname); chopped = ldns_dname_left_chop(dname); + ldns_rdf_deep_free(dname); ldns_dname_cat(hashed,chopped); RETVAL = ldns_nsec_covers_name(clone,hashed); ldns_rdf_deep_free(hashed); @@ -2,6 +2,7 @@ use Test::More; use Test::Fatal; use Encode; use Devel::Peek; +use utf8; BEGIN { use_ok( "Net::LDNS" => qw[:all] ) } @@ -12,10 +13,10 @@ if (exception {to_idn("whatever")} =~ /libidn not installed/) { } ok(has_idn(), 'Has IDN'); -my $encoded = to_idn( decode( 'utf8', 'annaröd.se' ) ); +my $encoded = to_idn( 'annaröd.se' ); is( $encoded, 'xn--annard-0xa.se', 'One name encoded right' ); -my @before = map { decode( 'utf8', $_ ) } ('annaröd.se', 'rindlöw.se', 'räksmörgås.se', 'nic.中國', 'iis.se'); +my @before = ('annaröd.se', 'rindlöw.se', 'räksmörgås.se', 'nic.中國', 'iis.se'); my @many = to_idn @before; is_deeply( \@many, @@ -23,6 +24,6 @@ is_deeply( 'Many encoded right' ); -like( exception { to_idn( decode( 'utf8', "ö" x 63 ) ) }, qr/Punycode/, 'Boom today' ); +like( exception { to_idn( "ö" x 63 ) }, qr/Punycode/, 'Boom today' ); done_testing; |