From 7000711159e8f7b4946055edea342cb4297b3c9c Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 10 Mar 2026 03:48:41 +0000 Subject: [PATCH] Bug 42047: Override configuration using html_scrubber.yaml This patch allows you to override any of the C4::Scrubber settings using a file called "html_scrubber.yaml" which is to be located in the same directory as your koha-conf.xml file. This allows people to override existing configurations in the event that they're not permissive enough (or are too permissive) e.g. The following YAML placed at /etc/koha/sites/kohadev/html_scrubber.yaml would make the additional_content scrubber only allow "div" --- additional_content: allow: ["div"] --- C4/Scrubber.pm | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/C4/Scrubber.pm b/C4/Scrubber.pm index 2ab662983a7..103cfc51250 100644 --- a/C4/Scrubber.pm +++ b/C4/Scrubber.pm @@ -23,8 +23,11 @@ use strict; use warnings; use Carp qw( croak ); use HTML::Scrubber; +use File::Basename qw( fileparse ); +use YAML::XS; use C4::Context; +use Koha::Config; my %scrubbertypes = ( default => {}, # place holder, default settings are below as fallbacks in call to constructor @@ -166,6 +169,49 @@ my %scrubbertypes = ( }, ); +override_default_settings( + { + settings => \%scrubbertypes, + } +); + +=head1 NAME + +C4::Scrubber + +=head1 API + +=head2 Functions + +=cut + +=head3 override_default_settings + + +=cut + +sub override_default_settings { + my ($args) = @_; + my $settings = $args->{settings}; + if ($settings) { + my ( $koha_conf_filename, $config_dir ) = fileparse( Koha::Config->guess_koha_conf ); + my $filename = sprintf( "%s/html_scrubber.yaml", $config_dir ); + if ( $filename && -f $filename ) { + my $override_settings = YAML::XS::LoadFile($filename); + if ( $override_settings && ref $override_settings && ref $override_settings eq 'HASH' ) { + foreach my $type ( keys %$override_settings ) { + $settings->{$type} = $override_settings->{$type}; + } + } + } + } + return $settings; +} + +=head3 new + +=cut + sub new { shift; # ignore our class we are wrapper my $type = (@_) ? shift : 'default'; -- 2.39.5