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

Fix handling of "file:" paths to non-existent files on Windows #26575

Merged
merged 1 commit into from
Feb 25, 2021

Conversation

candrews
Copy link
Contributor

@candrews candrews commented Feb 20, 2021

On Windows, for setAsText, if the text argument is a file: URL for a path that does not exist, Paths.get(text) is called where text is a file: URL, which doesn't work - the result is an InvalidPathException. The Windows part is important - this issue only manifests when running on Windows.

To fix this issue, also check that the resource isn't a file before calling Paths.get(). That way, resources that are files skip to the other branch.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 20, 2021
For setAsText, if the text argument is a file: URL for a path that does not exist, Paths.get(text) is called where text is a file: URL, which doesn't work - the result is an InvalidPathException.

To fix this issue, also check that the resource isn't a file before calling Paths.get(). That way, resources that are files skip to the other branch.
@candrews
Copy link
Contributor Author

I've added some tests to PathEditorTests to test for this issue. However, this issue only manifests when running on Windows (the newly added tests pass with and without this fix on other platforms).

@candrews candrews changed the title Fix handling of file: paths to non-existent files Fix handling of file: paths to non-existent files on Windows Feb 20, 2021
@jhoeller jhoeller self-assigned this Feb 22, 2021
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 22, 2021
@jhoeller jhoeller added this to the 5.3.5 milestone Feb 22, 2021
@jhoeller jhoeller changed the title Fix handling of file: paths to non-existent files on Windows Fix handling of "file:" paths to non-existent files on Windows Feb 22, 2021
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.2.x labels Feb 22, 2021
@jhoeller jhoeller merged commit ebf6fff into spring-projects:master Feb 25, 2021
jhoeller added a commit that referenced this pull request Feb 25, 2021
jhoeller added a commit that referenced this pull request Feb 25, 2021
For setAsText, if the text argument is a file: URL for a path that does not exist, Paths.get(text) is called where text is a file: URL, which doesn't work - the result is an InvalidPathException.

To fix this issue, also check that the resource isn't a file before calling Paths.get(). That way, resources that are files skip to the other branch.

Closes gh-26575
This was referenced Mar 17, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this pull request Mar 26, 2022
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) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants