aboutsummaryrefslogtreecommitdiffstats
path: root/Bugzilla/Util.pm
diff options
context:
space:
mode:
authorFrédéric Buclin <LpSolit@netscape.net>2018-02-18 18:25:30 +0100
committerFrédéric Buclin <LpSolit@netscape.net>2018-02-18 18:25:30 +0100
commitc52e3c6e8ad547ec035309994144fd22e2925267 (patch)
treed762218e6f71e302121d6112ad14deb5552201f8 /Bugzilla/Util.pm
parentd966c278e6c653a90343c739ac5a48f4127cf7e0 (diff)
parent37784703eba80cb61d1734a11e09b62fa0eaeae9 (diff)
downloadbugs-c52e3c6e8ad547ec035309994144fd22e2925267.tar
bugs-c52e3c6e8ad547ec035309994144fd22e2925267.tar.gz
bugs-c52e3c6e8ad547ec035309994144fd22e2925267.tar.bz2
bugs-c52e3c6e8ad547ec035309994144fd22e2925267.tar.xz
bugs-c52e3c6e8ad547ec035309994144fd22e2925267.zip
Sync with upstream release 5.0.4
Diffstat (limited to 'Bugzilla/Util.pm')
-rw-r--r--Bugzilla/Util.pm27
1 files changed, 26 insertions, 1 deletions
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index 9d388699d..9976b12d6 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -24,7 +24,7 @@ use parent qw(Exporter);
validate_email_syntax check_email_syntax clean_text
get_text template_var display_value disable_utf8
detect_encoding email_filter
- join_activity_entries);
+ join_activity_entries read_text write_text);
use Bugzilla::Constants;
use Bugzilla::RNG qw(irand);
@@ -40,6 +40,8 @@ use Scalar::Util qw(tainted blessed);
use Text::Wrap;
use Encode qw(encode decode resolve_alias);
use Encode::Guess;
+use File::Basename qw(dirname);
+use File::Temp qw(tempfile);
sub trick_taint {
require Carp;
@@ -107,6 +109,29 @@ sub html_quote {
return $var;
}
+sub read_text {
+ my ($filename) = @_;
+ open my $fh, '<:encoding(utf-8)', $filename;
+ local $/ = undef;
+ my $content = <$fh>;
+ close $fh;
+ return $content;
+}
+
+sub write_text {
+ my ($filename, $content) = @_;
+ my ($tmp_fh, $tmp_filename) = tempfile('.tmp.XXXXXXXXXX',
+ DIR => dirname($filename),
+ UNLINK => 0,
+ );
+ binmode $tmp_fh, ':encoding(utf-8)';
+ print $tmp_fh $content;
+ close $tmp_fh;
+ # File::Temp tries for secure files, but File::Slurp used the umask.
+ chmod(0666 & ~umask, $tmp_filename);
+ rename $tmp_filename, $filename;
+}
+
sub html_light_quote {
my ($text) = @_;
# admin/table.html.tmpl calls |FILTER html_light| many times.