[nginx-tests] Tests: charset tests with multiple buffers.

Maxim Dounin mdounin at mdounin.ru
Sun May 24 21:30:26 UTC 2026


details:   http://freenginx.org/hg/nginx-tests/rev/2d2b3edb6935
branches:  
changeset: 2057:2d2b3edb6935
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Tue May 19 22:11:57 2026 +0300
description:
Tests: charset tests with multiple buffers.

diffstat:

 charset_perl.t |  101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 101 insertions(+), 0 deletions(-)

diffs (106 lines):

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