Skip to content

AntPathMatcher with a custom separator doesn't match correctly a specific String #27683

@Nikolas-Charalambidis

Description

@Nikolas-Charalambidis

Affects: 5.3.10


Background:

I assume the AntPathMatcher matches (among othersú a path against a pattern if all below apply:

  • pattern and path are equal
  • they both contain only alphanumeric characters (no Ant-specific characters such as *, ? or { with } and no slashes / and \)

Reproducible sample:

The following code reproduces a strange behavior:

new AntPathMatcher().match("consent", "consent");             // true
new AntPathMatcher().match("consentreg", "consentreg");       // true

new AntPathMatcher("\\t").match("consent", "consent");        // true
new AntPathMatcher("\\t").match("consentreg", "consentreg");  // false

Do I assume the behavior wrongly? If so, would you describe the behavior and how to fix my use case?

Workaround:

As of now, I must check whether the pattern is not Ant pattern and check the equality first:

String string = "consentreg";
String pattern = "consentreg";
AntPathMatcher matcher = new AntPathMatcher("\\t");
boolean result = (!matcher.isPattern(pattern) && pattern.equals(string)) || getAntPathMatcher().match(pattern, string);
// true

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions