spring-projects / spring-projects/spring-framework

`URIEditor` encodes URI by default

Open
#35,241 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: core status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

package example;

import static org.assertj.core.api.Assertions.assertThat;

import java.net.URI;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

@SpringJUnitConfig
class URITests {

	private static final String URL = "http://username:p%40ssword@localhost/test";
	private static final String USER_INFO = "username:p@ssword";

	@Value(URL)
	private URI uri;

	@Test
	void testConversionService() {
		assertUserInfo(DefaultConversionService.getSharedInstance().convert(URL, URI.class));
	}

	@Test
	void testURI() throws Exception {
		assertUserInfo(new URI(URL));
	}

	@Test
	void testBind() {
		assertUserInfo(this.uri);
	}

	private void assertUserInfo(URI uri) {
		assertThat(uri.getUserInfo()).isEqualTo(USER_INFO);
	}
}

Two tests pass but one test failed with:

org.opentest4j.AssertionFailedError: 
expected: "username:p@ssword"
 but was: "username:p%40ssword"
	at example.URITests.assertUserInfo(URITests.java:37)
	at example.URITests.testBind(URITests.java:33)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.5.4'
	id 'io.spring.dependency-management' version 'latest.release'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '21'

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
	useJUnitPlatform()
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied URITests reproducer, especially testBind and the @Value URL binding, then trace the URIEditor conversion path used there. Compare it with DefaultConversionService.convert and new URI(URL). Done means the binding assertion yields username:p@ssword without breaking the existing passing cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.