[PATCH] Tests: charset tests with multiple buffers
Maxim Dounin
mdounin at mdounin.ru
Tue May 19 19:12:23 UTC 2026
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1779217917 -10800
# Tue May 19 22:11:57 2026 +0300
# Node ID 2d2b3edb6935fa91060b3e2e804eca7927b93e81
# Parent dca9f4b8950e9e8473eead25c82d2314365f8481
Tests: charset tests with multiple buffers.
diff --git a/charset_perl.t b/charset_perl.t
new file mode 100644
--- /dev/null
+++ b/charset_perl.t
@@ -0,0 +1,101 @@
+#!/usr/bin/perl
+
+# (C) Maxim Dounin
+
+# Tests for charset filter, extended tests using embedded perl.
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+my $t = Test::Nginx->new()->has(qw/http charset perl/)->plan(1)
+ ->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+http {
+ %%TEST_GLOBALS_HTTP%%
+
+ charset test;
+ source_charset utf-8;
+
+ charset_map test utf-8 {
+ 43 C2A9 ; # (C)
+ 54 E284A2 ; # trade mark sign
+ }
+
+ postpone_output 0;
+
+ server {
+ listen 127.0.0.1:8080;
+ server_name localhost;
+
+ location / {
+ perl 'sub {
+ my $r = shift;
+ $r->send_http_header("text/html");
+ return OK if $r->header_only;
+
+ # 2-byte character
+
+ $r->print("\xc2\xa9");
+ $r->print("\xc2");
+ $r->print("\xa9");
+
+ # 3-byte character
+
+ $r->print("\xe2\x84\xa2");
+ $r->print("\xe2");
+ $r->print("\x84");
+ $r->print("\xa2");
+
+ # 4-byte character
+
+ $r->print("\xf0\x90\x80\x80");
+ $r->print("\xf0");
+ $r->print("\x90");
+ $r->print("\x80");
+ $r->print("\x80");
+
+ return OK;
+ }';
+ }
+ }
+}
+
+EOF
+
+$t->run();
+
+###############################################################################
+
+TODO: {
+local $TODO = 'not yet'
+ unless $t->has_version('1.31.1');
+todo_skip 'might coredump', 1
+ unless $t->has_version('1.31.1')
+ or $ENV{TEST_NGINX_UNSAFE};
+
+like(http_get('/multi'), qr/^CCTT𐀀𐀀$/m, 'multiple buffers');
+
+}
+
+###############################################################################
More information about the nginx-devel
mailing list