Skip to content

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

Closed
@ilya-komlev

Description

@ilya-komlev

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions