Skip to content

Path with several "{...}" incorrectly parsed #358

@dedece35

Description

@dedece35

Explanation

When a path contains several variables with "{}" characters, the template computed for this URL is incorrect.

Example with URL template computed correctly :

  • path : /avis/by_id_utilisateur-{id_utilisateur}
  • template computed : /avis/by_id_utilisateur-{}

Example with URL template incorrect :

  • path : /avis/by_id_utilisateur-{id_utilisateur}_code_support-{code_support}
  • template computed : /avis/by_id_utilisateur-{}

If we have an API with these two paths, /avis/by_id_utilisateur-{id_utilisateur} and /avis/by_id_utilisateur-{id_utilisateur}_code_support-{code_support}
thus de verification will fail with an error Two path items have the same signature: /avis/by_id_utilisateur-{}.
This is because of wrong templates computed during the control process.

Analysis / Solution

After, an analysis of code, this template URL computation was made by a method that does a replace from a regex pattern.

...
public class PathsDiff {
  private static final String REGEX_PATH = "\\{([^/]+)}";
  ...  
  private static String normalizePath(String path) {
    return path.replaceAll(REGEX_PATH, "{}");
  }
  ...
}

This pattern is wrong, we should have "\{([^/{}]+)}" to exclude "{" and "}" from detection.
I tested this pattern locally and it's ok for me with this last regex pattern.

If you want I can correct it. I will create a PR if nobody does it before me :p

thanks.

David.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions