From e7497fc00f0da3dbf3d104434fe86be6e56ace93 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Thu, 13 Feb 2020 23:22:00 -0800 Subject: [PATCH] Add uri_escape to FuncBuiltins --- Plugins/FuncBuiltins.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Plugins/FuncBuiltins.pm b/Plugins/FuncBuiltins.pm index 099f0f3e..9b0b53e0 100644 --- a/Plugins/FuncBuiltins.pm +++ b/Plugins/FuncBuiltins.pm @@ -55,6 +55,13 @@ sub initialize { subref => sub { $self->func_unquote(@_) } } ); + $self->{pbot}->{functions}->register('uri_escape', + { + desc => 'percent-encode unsafe URI characters', + usage => 'uri_escape ', + subref => sub { $self->func_uri_escape(@_) } + } + ); } sub unload { @@ -64,6 +71,7 @@ sub unload { $self->{pbot}->{functions}->unregister('uc'); $self->{pbot}->{functions}->unregister('lc'); $self->{pbot}->{functions}->unregister('unquote'); + $self->{pbot}->{functions}->unregister('uri_escape'); } sub func_unquote { @@ -101,4 +109,11 @@ sub func_lc { return lc $text; } +use URI::Escape qw/uri_escape_utf8/; +sub func_uri_escape { + my $self = shift; + my $text = "@_"; + return uri_escape_utf8($text); +} + 1;