You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Make a directory C:\[dir] with a file file.txt inside.
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();
}
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)
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)
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 inFileHeaders.RELATIVE_PATH
header is incorrect (C:\[dir]\file.txt
instead offile.txt
). There is a misuse ofMatcher.quoteReplacement
insidedoReceive
whereFileHeaders.RELATIVE_PATH
gets set.Pattern.quote
seems to be a better fit, or something likeStringUtils.replaceOnce
.To Reproduce
C:\[dir]
with a filefile.txt
inside.IntegrationFlow
like this:Expected behavior
Expecting just
file.txt
in the output.Sample
https://github.com/ilya-komlev/spring-integration-bug-202410251558
The text was updated successfully, but these errors were encountered: