Skip to content

Broken backward compatibility of namedGroups() method #26

@gaborauth

Description

@gaborauth

Hi!

I've just found a possible bug in the library, the following snippet will works with 0.2.6 and throw an exception with 0.2.7:

        final String regex = "/teamDrawer/(?<roomId>.*)";
        final String url = "/teamDrawer/12345";

        final Matcher matcher = Pattern.compile(regex).matcher(url);
        final Integer count = matcher.namedGroups().size();
        final Integer mapCount = matcher.namedGroups().get(0).size();
        final String value = matcher.namedGroups().get(0).get("roomId");

The root cause is the .namedGroups() can only callable once in the version 0.2.7, with the other calls it will return an empty list, maybe the !matcher.hitEnd() prevent it to fill up the list of maps again.

--

I'm using it with Kotlin, so, it turned out that it was called several times in under the hood:

        Pattern.compile(pattern).matcher(url).let {
            when {
                it.matches() && it.groupCount() > 0 -> Router.Parameters.Match(it.namedGroups().firstOrNull() ?: mapOf())
                ... -> ...
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions