From 1e0b19a807e1540d2afb5bc3c1d5aea8acdad3cd Mon Sep 17 00:00:00 2001 From: Sean Porth Date: Mon, 12 Sep 2022 13:38:40 -0400 Subject: [PATCH] shibui-2341 better url encoding, utf8 encoding of names --- bulk-upload/README.md | 2 +- bulk-upload/docker-build/Dockerfile | 2 +- bulk-upload/docker-build/shibui-md-upload.pl | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bulk-upload/README.md b/bulk-upload/README.md index 23462d5ca..02196fba9 100644 --- a/bulk-upload/README.md +++ b/bulk-upload/README.md @@ -42,6 +42,6 @@ If you prefer to build the image yourself, `cd docker-build;docker build -t unic ### running without docker ### The docker-build/shibui-md-upload.pl script can be run manually. -Depending on OS you may need to install some additional non dist Perl modules. REST::Client , XML::LibXML , JSON , Config::File +Depending on OS you may need to install some additional non dist Perl modules. REST::Client , XML::LibXML , JSON , Config::File , URI::Encode `perl shibui-md-upload.pl -c -m -e (enable metadata source after upload)` diff --git a/bulk-upload/docker-build/Dockerfile b/bulk-upload/docker-build/Dockerfile index dd7384667..8c1efcba9 100644 --- a/bulk-upload/docker-build/Dockerfile +++ b/bulk-upload/docker-build/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER sporth@unicon.net RUN apt-get clean \ && apt-get -y update \ - && apt-get install -y librest-client-perl libconfig-file-perl jq libxml-libxml-perl libjson-perl + && apt-get install -y librest-client-perl libconfig-file-perl jq libxml-libxml-perl libjson-perl liburi-encode-perl WORKDIR /opt COPY shibui-md-upload.pl /opt/shibui-md-upload.pl diff --git a/bulk-upload/docker-build/shibui-md-upload.pl b/bulk-upload/docker-build/shibui-md-upload.pl index 160559c6d..4f24334e3 100755 --- a/bulk-upload/docker-build/shibui-md-upload.pl +++ b/bulk-upload/docker-build/shibui-md-upload.pl @@ -12,6 +12,7 @@ use XML::LibXML::XPathContext; use Encode; use JSON; +use URI::Encode; ##process arguments our ($opt_e,$opt_m,$opt_c); @@ -201,10 +202,13 @@ sub call_api { my $xml = shift; my $enable = shift; my ($params,$code,$result); + my $encoder = URI::Encode->new({encode_reserved => 1}); my $utf8 = encode_utf8($xml); + my $utf8_name = encode_utf8($name); + my $ename = $encoder->encode($name); - $params = "?spName=$name"; + $params = "?spName=$ename"; $params .= "&enableService=true" if ($enable); $client->addHeader('Content-Type', "application/xml; charset='utf8'"); @@ -226,18 +230,18 @@ sub call_api { my $eresult = $client->responseContent(); if ($ecode == 200 || $ecode == 201) { - print "$ecode: entity $name uploaded sucessfully and enabled\n"; + print "$ecode: entity $utf8_name uploaded sucessfully and enabled\n"; } else { - print "$ecode: entity $name uploaded sucessfully but enabling failed:\n"; + print "$ecode: entity $utf8_name uploaded sucessfully but enabling failed:\n"; open(my $pipe, '|-', "jq ."); print $pipe $eresult; } } else { - print "$code: entity $name uploaded sucessfully\n"; + print "$code: entity $utf8_name uploaded sucessfully\n"; } } elsif ($code == 409) { - print "$code: entity $name already exists\n"; + print "$code: entity $utf8_name already exists\n"; } elsif ($code == 500) { print "$code: $result\n"; } else {