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

FileReadingMessageSource doesn't set FileHeaders.RELATIVE_PATH header value corretly #9594

Closed
ilya-komlev opened this issue Oct 25, 2024 · 0 comments

Comments

@ilya-komlev
Copy link

In what version(s) of Spring Integration are you seeing this issue?

6.3.5

Describe the bug

When FileReadingMessageSource's directory contains something like [dir] or (dir) in its absolute path (C:\[dir], /user/(dir), etc.) the value that ends up in FileHeaders.RELATIVE_PATH header is incorrect (C:\[dir]\file.txt instead of file.txt). There is a misuse of Matcher.quoteReplacement inside doReceive where FileHeaders.RELATIVE_PATH gets set. Pattern.quote seems to be a better fit, or something like StringUtils.replaceOnce.

To Reproduce

  1. Make a directory C:\[dir] with a file file.txt inside.
  2. Make and run a simple Spring Boot Integration app with a single IntegrationFlow like this:
@Bean
IntegrationFlow flow() {
	File dir = new File("C:\\[dir]");
	return IntegrationFlow.from(Files.inboundAdapter(dir))                
			.handle(msg -> System.out.println(msg.getHeaders().get(FileHeaders.RELATIVE_PATH)))
			.get();
}

Expected behavior

Expecting just file.txt in the output.

Sample

https://github.com/ilya-komlev/spring-integration-bug-202410251558

@ilya-komlev ilya-komlev added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Oct 25, 2024
@artembilan artembilan added this to the 6.4.0 milestone Oct 25, 2024
@artembilan artembilan added in: file for: backport-to-6.2.x for: backport-to-6.3.x and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Oct 25, 2024
spring-builds pushed a commit that referenced this issue Oct 25, 2024
Fixes: #9594
Issue link: #9594

The `String.replaceFirst()` for directory with `[]` or `()` leads to a regex execution
which does not really replace the root path because of mismatch between regex and file path.
Essentially, the `Matcher.quoteReplacement()` does not do the trick we would expect from it.

* Use `Path.relativize()` API instead which works in canonical paths and proper file separators

(cherry picked from commit 9149409)
spring-builds pushed a commit that referenced this issue Oct 25, 2024
Fixes: #9594
Issue link: #9594

The `String.replaceFirst()` for directory with `[]` or `()` leads to a regex execution
which does not really replace the root path because of mismatch between regex and file path.
Essentially, the `Matcher.quoteReplacement()` does not do the trick we would expect from it.

* Use `Path.relativize()` API instead which works in canonical paths and proper file separators

(cherry picked from commit 9149409)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants