From 4ba66357606f638d8a8da4258644358035cd720d Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 24 Sep 2014 17:01:00 +0200 Subject: [PATCH] Bug 12758: Workaround for loading stylesheets over https Content-Type: text/plain; charset=utf-8 LibXML does not like https references when loading xml with the location parameter. This can be resolved by reading the file into a string and passing it to load_xml via the string parameter. Note that LWP::UserAgent will only load the file if LWP::Protocol::https is installed. This is an optional perl dependency in Koha. I mark it as required now. Also note that if your stylesheet contains an import with a https reference, this fix is not enough. The load_xml call will not fail, but the succeeding call to parse_stylesheet will still fail. As a workaround, make your import file accessible via http. NOTE: Some code taken from report 12172. With thanks to Martin Renvoize. Test plan: Take for example OPACXSLTDetailsDisplay and replace it by a https ref. Check opac detail display. Note that replacing OPACXSLTResultsDisplay by some https ref would also test repeating the call. --- C4/Installer/PerlDependencies.pm | 4 ++-- Koha/XSLT_Handler.pm | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index ad1f5a6..50887ec 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -738,8 +738,8 @@ our $PERL_DEPS = { 'min_ver' => '0.91', }, 'LWP::Protocol::https' => { - 'usage' => 'OverDrive integration', - 'required' => '0', + 'usage' => 'Core', + 'required' => '1', 'min_ver' => '5.836', }, }; diff --git a/Koha/XSLT_Handler.pm b/Koha/XSLT_Handler.pm index 0779f2f..a4c854a 100644 --- a/Koha/XSLT_Handler.pm +++ b/Koha/XSLT_Handler.pm @@ -311,7 +311,18 @@ sub _load { sub _load_xml_args { my $self = shift; - return $_[1]? { 'string' => $_[1]//'' }: { 'location' => $_[0]//'' }; + my $https_code = $self->_https_workaround(@_); + return $https_code || $_[1]? + { 'string' => $https_code // $_[1] }: { 'location' => $_[0]//'' }; +} + +sub _https_workaround { # Routine added for bug 12758 (part 1) + my ( $self, $file, $code ) = @_; + return if $file!~/^https/i; + require LWP::UserAgent; + my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } ); + my $resp = $ua->get( $file ); + return $resp->decoded_content if $resp->is_success; #undef otherwise } # _set_error -- 1.7.7.6