Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UrlResource getFilename() suddenly returns null for certain paths #31718

Closed
bushwakko opened this issue Nov 29, 2023 · 1 comment
Closed

UrlResource getFilename() suddenly returns null for certain paths #31718

bushwakko opened this issue Nov 29, 2023 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@bushwakko
Copy link

bushwakko commented Nov 29, 2023

After upgrading to spring-core 6.1.1 UrlResource("file:test").getFilename() returns null. On older versions 6.0.x i returned "test".

The problem seems to be caused by the fact that older version had field uri set to null and url set, but on 6.1.1 both url and uri is set.

This changes the behavior of getFilename, from getting the filename from url, to failing to get it from uri:

	public String getFilename() {
		if (this.uri != null) {
			// URI path is decoded and has standard separators
			return StringUtils.getFilename(this.uri.getPath());
		}
		else {
			String filename = StringUtils.getFilename(StringUtils.cleanPath(this.url.getPath()));
			return (filename != null ? URLDecoder.decode(filename, StandardCharsets.UTF_8) : null);
		}
	}
@jhoeller jhoeller self-assigned this Nov 29, 2023
@jhoeller jhoeller added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) labels Nov 29, 2023
@jhoeller jhoeller added this to the 6.1.2 milestone Nov 29, 2023
@bushwakko
Copy link
Author

Doing UrlResource(URL("file:test")) ensures the field uri is set to null, and the getFilename() and you get the same behavior as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

2 participants