From faec2a411bc62f0fd17999bf35f925bd1771b33c Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Mon, 14 Dec 2020 01:36:46 +0300 Subject: [PATCH] Revert "Add limit when reading file contents" This reverts commit b59464667915cb08ea4913d7688de22b8969b9e9. --- filemin/edit_file.cgi | 27 ++++++++++++--------------- lang/en | 2 -- web-lib-funcs.pl | 20 ++------------------ 3 files changed, 14 insertions(+), 35 deletions(-) diff --git a/filemin/edit_file.cgi b/filemin/edit_file.cgi index 11f8ab5af..c2705e413 100755 --- a/filemin/edit_file.cgi +++ b/filemin/edit_file.cgi @@ -7,24 +7,21 @@ get_paths(); my $file = &simplify_path($cwd . '/' . $in{'file'}); &check_allowed_path($file); -my $data = &read_file_contents($file, $in{'limit'}); +my $data = &read_file_contents($file); my $encoding_name; -if ($in{'binary'}) { - $data =~ s/[^[:print:]\n\r\t]/ /g; -} else { - eval "use Encode::Detect::Detector;"; - if (!$@) { - $encoding_name = Encode::Detect::Detector::detect($data); - } - my $forced = ($data =~ /(.*\n)(.*\n)(.*\n)/); - $forced = (($1 . $2 . $3) =~ /coding[=:]\s*([-\w.]+)/); - if ((lc(get_charset()) eq "utf-8" && ($encoding_name && lc($encoding_name) ne "utf-8")) || $forced) { - if ($forced) { - $encoding_name = "$1"; - } - eval {$data = Encode::encode('utf-8', Encode::decode($encoding_name, $data))}; +eval "use Encode::Detect::Detector;"; +if (!$@) { + $encoding_name = Encode::Detect::Detector::detect($data); +} +my $forced = ($data =~ /(.*\n)(.*\n)(.*\n)/); +$forced = (($1 . $2 . $3) =~ /coding[=:]\s*([-\w.]+)/); +if ((lc(get_charset()) eq "utf-8" && ($encoding_name && lc($encoding_name) ne "utf-8")) || $forced) { + if ($forced) { + $encoding_name = "$1"; } + use Encode qw( encode decode ); + eval {$data = Encode::encode('utf-8', Encode::decode($encoding_name, $data))}; } &ui_print_header(undef, $text{'edit_file'}, ""); diff --git a/lang/en b/lang/en index a388d3bea..10b60d5f9 100644 --- a/lang/en +++ b/lang/en @@ -380,6 +380,4 @@ nice_size_b=bytes langauto_include=Include machine translations -edit_truncated=truncated $1 of data - __norefs=1 diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 5ba866bc2..f325a6e3d 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -10219,7 +10219,7 @@ else { } } -=head2 read_file_contents(file, limit) +=head2 read_file_contents(file) Given a filename, returns its complete contents as a string. Effectively the same as the Perl construct `cat file`. @@ -10227,27 +10227,11 @@ the same as the Perl construct `cat file`. =cut sub read_file_contents { -my ($file, $limit) = @_; +my ($file) = @_; &open_readfile(FILE, $file) || return undef; local $/ = undef; my $rv = ; close(FILE); -if ($limit) { - my ($a, $b, $c, $s, $e, $f, $g, $h); - $a = $rv =~ tr/\n//; - $h = length($rv); - $f = int($limit); - if ($f && $h + $a > $f) { - $b = "\n\n\n[--- @{[&text('edit_truncated', &nice_size($h - $f))]} ---]\n\n\n"; - $g = int(($f / 2) + (length($b) / 2)); - $s = substr($rv, 0, $g); - $s =~ s/\n$//; - $s = $s . $b; - $e = substr($rv, ($g * -1)); - $e =~ s/^\n//; - $rv = $s . $e; - } - } return $rv; }