Skip to content

Regression in Jetty 12.1: Invalid UTF-8 exception for application/x-www-form-urlencoded; charset=iso-8859-1 #14646

@kelunik

Description

@kelunik

Jetty version(s)
12.1.7 (12.1.x)

Jetty Environment
core

HTTP version
2

Java version/vendor (use: java -version)
25 Corretto

OS type/version
any

Description

Jetty 12.1.7 doesn't correctly handle ISO-8859-1 encoded requests and returns an error response instead of the expected 200 OK with the example below. The same code is working fine in Jetty 12.0.33.

How to reproduce?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.kelunik</groupId>
    <artifactId>jetty-bug-charset</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>25</maven.compiler.source>
        <maven.compiler.target>25</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.jetty.http2</groupId>
            <artifactId>jetty-http2-server</artifactId>
            <version>12.1.7</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.17</version>
        </dependency>
    </dependencies>
</project>
package com.kelunik;

import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.util.Callback;

import java.nio.ByteBuffer;

public class Main {
    static void main() throws Exception {
        Server server = new Server();

        ServerConnector connector = new ServerConnector(server, new HTTP2ServerConnectionFactory());
        server.addConnector(connector);

        server.setHandler(new Handler.Abstract() {
            @Override
            public boolean handle(Request request, Response response, Callback callback) throws Exception {
                Request.getParameters(request);

                response.write(true, ByteBuffer.wrap(new byte[0]), callback);

                return true;
            }
        });

        server.start();
    }
}

curl --http2-prior-knowledge -v http://localhost:52240 -H 'content-type: application/x-www-form-urlencoded; charset=iso-8859-1' --data 'name=%e9'

See #14614 for a possible fix.

Metadata

Metadata

Assignees

Labels

BugFor general bugs on Jetty side

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions