Skip to content

Commit d4dd2f7

Browse files
committed
Revert 3a1bbc7 in PR #1885 to postpone making Unicode::UTF8 mandatory.
1 parent 68aa5b7 commit d4dd2f7

File tree

7 files changed

+60
-31
lines changed

7 files changed

+60
-31
lines changed

.github/workflows/make-check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
--verbose --no-interactive
6262
--with-develop
6363
--with-feature=Data::Password --with-feature=ldap
64-
--with-feature=smime
64+
--with-feature=safe-unicode --with-feature=smime
6565
--with-feature=soap --with-feature=sqlite
6666
${{ startsWith(matrix.os, 'macos') && '--with-feature=macos' || '' }}
6767
- name: Run tests

.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- . ~/bashrc
88
- coverage-install
99
- coverage-setup
10-
- cpanm --quiet --notest --installdeps --with-develop --with-feature=Data::Password --with-feature=ldap --with-feature=smime --with-feature=soap --with-feature=sqlite .
10+
- cpanm --quiet --notest --installdeps --with-develop --with-feature=Data::Password --with-feature=ldap --with-feature=safe-unicode --with-feature=smime --with-feature=soap --with-feature=sqlite .
1111
- autoreconf -i
1212
- ./configure
1313
- cd src; make; cd ..

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ before_install:
2525

2626
install:
2727
- cpan-install --coverage
28-
- cpanm --installdeps --notest --with-develop --with-feature=Data::Password --with-feature=ldap --with-feature=smime --with-feature=soap --with-feature=sqlite .
28+
- cpanm --installdeps --notest --with-develop --with-feature=Data::Password --with-feature=ldap --with-feature=safe-unicode --with-feature=smime --with-feature=soap --with-feature=sqlite .
2929

3030
before_script:
3131
- coverage-setup

cpanfile

+11-11
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,6 @@ requires 'Time::HiRes', '>= 1.29';
150150
# Used to get Unix time from local time
151151
requires 'Time::Local', '>= 1.23';
152152

153-
# Normalizes file names represented by Unicode.
154-
# Note: Perl 5.8.1 bundles version 0.23.
155-
# Note: Perl 5.10.1 bundles 1.03 (per Unicode 5.1.0).
156-
requires 'Unicode::Normalize', '>= 1.03';
157-
158-
# Sanitizes inputs with Unicode text.
159-
requires 'Unicode::UTF8', '>= 0.58';
160-
161153
# Used to create URI containing non URI-canonical characters.
162154
# Note: '3.28' is the version included in URI-1.35.
163155
requires 'URI::Escape', '>= 3.28';
@@ -198,6 +190,13 @@ recommends 'Net::DNS', '>= 0.65';
198190
# This is required if you set "list_check_smtp" sympa.conf parameter, used to check existing aliases before mailing list creation.
199191
recommends 'Net::SMTP';
200192

193+
# Normalizes file names represented by Unicode
194+
# Note: Perl 5.8.1 bundles version 0.23.
195+
# Note: Perl 5.10.1 bundles 1.03 (per Unicode 5.1.0).
196+
recommends 'Unicode::Normalize', '>= 1.03';
197+
198+
recommends 'Unicode::UTF8', '>= 0.60';
199+
201200
### Features
202201
##
203202

@@ -325,9 +324,10 @@ feature 'soap', 'Required if you want to run the Sympa SOAP server that provides
325324
};
326325

327326
feature 'safe-unicode', 'Sanitizes inputs with Unicode text.' => sub {
328-
# Note: These became required (>=6.2.73b).
329-
#requires 'Unicode::Normalize', '>= 1.03';
330-
#requires 'Unicode::UTF8', '>= 0.58';
327+
# Note: Perl 5.8.1 bundles version 0.23.
328+
# Note: Perl 5.10.1 bundles 1.03 (per Unicode 5.1.0).
329+
requires 'Unicode::Normalize', '>= 1.03';
330+
requires 'Unicode::UTF8', '>= 0.60';
331331
};
332332

333333
on 'test' => sub {

src/cgi/wwsympa.fcgi.in

+16-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use IO::File qw();
3939
use MIME::EncWords;
4040
use MIME::Lite::HTML;
4141
use POSIX qw();
42-
use Unicode::UTF8;
4342
use URI;
4443
use Data::Dumper; # tentative
4544

@@ -53,6 +52,10 @@ BEGIN {
5352
and $Archive::Zip::SimpleZip::VERSION;
5453
}
5554

55+
BEGIN {
56+
eval 'use Unicode::UTF8 qw()';
57+
}
58+
5659
use Sympa;
5760
use Sympa::Archive;
5861
use Conf;
@@ -1060,7 +1063,18 @@ while ($query = Sympa::WWW::FastCGI->new) {
10601063
while (my ($k, $v) = each %in) {
10611064
next if ref $v;
10621065
next if Encode::is_utf8($v);
1063-
unless (Unicode::UTF8::valid_utf8($v)) {
1066+
1067+
my $valid_utf8;
1068+
if ($Unicode::UTF8::VERSION) {
1069+
$valid_utf8 = Unicode::UTF8::valid_utf8($v);
1070+
} else {
1071+
eval {
1072+
my $u = $v;
1073+
Encode::decode('UTF-8', $u, Encode::FB_CROAK());
1074+
$valid_utf8 = 1;
1075+
};
1076+
}
1077+
unless ($valid_utf8) {
10641078
$log->syslog('err', 'Parameter in invalid UTF-8 %s="%s": Ignored',
10651079
$k, sprintf("\\x%*v02X", "\\x", $v));
10661080
delete $in{$k};

src/lib/Sympa/Tools/Text.pm

+17-7
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ use MIME::EncWords;
3939
use Text::LineFold;
4040
use Unicode::GCString;
4141
use URI::Escape qw();
42-
use Unicode::Normalize qw();
43-
use Unicode::UTF8;
42+
BEGIN { eval 'use Unicode::Normalize qw()'; }
43+
BEGIN { eval 'use Unicode::UTF8 qw()'; }
4444

4545
use Sympa::Language;
4646
use Sympa::Regexps;
@@ -141,11 +141,15 @@ sub canonic_text {
141141
my $utext;
142142
if (Encode::is_utf8($text)) {
143143
$utext = $text;
144-
} else {
144+
} elsif ($Unicode::UTF8::VERSION) {
145145
no warnings 'utf8';
146146
$utext = Unicode::UTF8::decode_utf8($text);
147+
} else {
148+
$utext = Encode::decode_utf8($text);
149+
}
150+
if ($Unicode::Normalize::VERSION) {
151+
$utext = Unicode::Normalize::normalize('NFC', $utext);
147152
}
148-
$utext = Unicode::Normalize::normalize('NFC', $utext);
149153

150154
# Remove DOS linefeeds (^M) that cause problems with Outlook 98, AOL,
151155
# and EIMS:
@@ -309,8 +313,13 @@ sub guessed_to_utf8 {
309313
and length $text
310314
and $text =~ /[^\x00-\x7F]/;
311315

312-
my $utf8 = Unicode::UTF8::decode_utf8($text)
313-
if Unicode::UTF8::valid_utf8($text);
316+
my $utf8;
317+
if ($Unicode::UTF8::VERSION) {
318+
$utf8 = Unicode::UTF8::decode_utf8($text)
319+
if Unicode::UTF8::valid_utf8($text);
320+
} else {
321+
$utf8 = eval { Encode::decode_utf8($text, Encode::FB_CROAK()) };
322+
}
314323
unless (defined $utf8) {
315324
foreach my $charset (map { $_ ? @$_ : () } @legacy_charsets{@langs}) {
316325
$utf8 =
@@ -323,7 +332,8 @@ sub guessed_to_utf8 {
323332
}
324333

325334
# Apply NFC: e.g. for modified-NFD by Mac OS X.
326-
$utf8 = Unicode::Normalize::normalize('NFC', $utf8);
335+
$utf8 = Unicode::Normalize::normalize('NFC', $utf8)
336+
if $Unicode::Normalize::VERSION;
327337

328338
return Encode::encode_utf8($utf8);
329339
}

t/Tools_Text.t

+13-8
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ is $dec, $unicode_email, 'decode_filesystem_safe, Unicode';
4646
# ToDo: foldcase()
4747
# ToDo: wrap_text()
4848

49-
# Noncharacters: U+D800, U+10FFE, U+110000, U+200000
50-
is Sympa::Tools::Text::canonic_text(
51-
"\xED\xA0\x80\n\xF4\x8F\xBF\xBE\n\xF4\x90\x80\x80\n\xF8\x88\x80\x80\x80\n"
52-
),
53-
Encode::encode_utf8(
54-
"\x{FFFD}\x{FFFD}\x{FFFD}\n\x{FFFD}\n\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\n\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\n"
55-
),
56-
'canonic_text';
49+
SKIP: {
50+
skip 'Unicode::Normalize and Unicode::UTF8 required.'
51+
unless $Unicode::Normalize::VERSION and $Unicode::UTF8::VERSION;
52+
53+
# Noncharacters: U+D800, U+10FFE, U+110000, U+200000
54+
is Sympa::Tools::Text::canonic_text(
55+
"\xED\xA0\x80\n\xF4\x8F\xBF\xBE\n\xF4\x90\x80\x80\n\xF8\x88\x80\x80\x80\n"
56+
),
57+
Encode::encode_utf8(
58+
"\x{FFFD}\x{FFFD}\x{FFFD}\n\x{FFFD}\n\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\n\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\n"
59+
),
60+
'canonic_text';
61+
}
5762

5863
done_testing();

0 commit comments

Comments
 (0)