Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing wildcard matcher #25

Merged

Conversation

Daanoz
Copy link
Contributor

@Daanoz Daanoz commented Sep 27, 2018

I've found an issue where nested wildcards are not matched. I've rewritten the folder matcher code to use recursion to find the correct folder.

Assuming the a folder structure like:

└── api
    └── lvl1
        ├── __p1__
        │   └──   lvl2
        │       ├──  __p2__
        │       │   └──   lvl3
        │       │       └──  GET.json (a)
        │       └──   1
        │           └──   lvl3
        │               └──  GET.json (b)
        └── 1
            └──   lvl2
                ├──  __p2__
                │   └──   lvl3
                │       └──  GET.json (c)
                └──   1
                    └──   lvl3
                        └──  GET.json (d)

Desired situation:
GET lvl1/1/lvl2/1/lvl3 => (d)
GET lvl1/8/lvl2/1/lvl3 => (b)
GET lvl1/1/lvl2/8/lvl3 => (c)
GET lvl1/8/lvl2/8/lvl3 => (a)

At the moment, if file (d) would not exist, it will result in a 404 not found when lvl1/1/lvl2/1/lvl3 is requested. Expected is that (c) would be returned. This is because the folder lvl1/1/lvl2/1 actually does exist, and the matcher doesn't look back once it finds an non existent folder.

With the changed code, the matching strategy will be as follows (first one that matches wins), stars indicate where a possible wildcard could be:

  1. "/lvl1/2/lvl2/2/lvl3"
  2. "/lvl1/2/lvl2/2/*"
  3. "/lvl1/2/lvl2/*/lvl3"
  4. "/lvl1/2/lvl2/*/*"
  5. "/lvl1/2/*/2/lvl3"
  6. "/lvl1/2/*/2/*"
  7. "/lvl1/2/*/*/lvl3"
  8. "/lvl1/2/*/*/*"
  9. "/lvl1/*/lvl2/2/lvl3"
  10. "/lvl1/*/lvl2/2/*"
  11. "/lvl1/*/lvl2/*/lvl3"
  12. "/lvl1/*/lvl2/*/*"
  13. "/lvl1/*/*/2/lvl3"
  14. "/lvl1/*/*/2/*"
  15. "/lvl1/*/*/*/lvl3"
  16. "/lvl1/*/*/*/*"
  17. "/*/2/lvl2/2/lvl3"
  18. "/*/2/lvl2/2/*"
  19. "/*/2/lvl2/*/lvl3"
  20. "/*/2/lvl2/*/*"
  21. "/*/2/*/2/lvl3"
  22. "/*/2/*/2/*"
  23. "/*/2/*/*/lvl3"
  24. "/*/2/*/*/*"
  25. "/*/*/lvl2/2/lvl3"
  26. "/*/*/lvl2/2/*"
  27. "/*/*/lvl2/*/lvl3"
  28. "/*/*/lvl2/*/*"
  29. "/*/*/*/2/lvl3"
  30. "/*/*/*/2/*"
  31. "/*/*/*/*/lvl3"
  32. "/*/*/*/*/*"

@codecov
Copy link

codecov bot commented Sep 27, 2018

Codecov Report

Merging #25 into master will increase coverage by 0.72%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #25      +/-   ##
==========================================
+ Coverage   96.38%   97.11%   +0.72%     
==========================================
  Files           1        1              
  Lines          83      104      +21     
==========================================
+ Hits           80      101      +21     
  Misses          3        3
Impacted Files Coverage Δ
api-mocker.js 97.11% <100%> (+0.72%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 455a465...8511362. Read the comment docs.

@muratcorlu muratcorlu merged commit c8d0ac4 into muratcorlu:master Sep 27, 2018
@muratcorlu
Copy link
Owner

Thanks for this great contribution @Daanoz! 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants