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

Add empty array fallback to regex match #229

Merged
merged 2 commits into from
Nov 28, 2020
Merged

Add empty array fallback to regex match #229

merged 2 commits into from
Nov 28, 2020

Conversation

evans
Copy link
Contributor

@evans evans commented Nov 27, 2020

Thank you for creating this! When extracting annotations and no doc strings are found, match returns null. When we try to iterate over the resulting null, we get a type error. This adds an empty array fallback to prevent that error and exit.

I thought about adding a warning that no docs were found here, though handling that in the caller seems more appropriate. Let me know if you'd prefer that to happen here!

reference for match

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#Return_value

When no results are found `match` returns `null`. When we try to iterate over the resulting `null`, we get a type error. This adds an empty array fallback to prevent that error.

developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#Return_value
@evans
Copy link
Contributor Author

evans commented Nov 27, 2020

I added some tests that needed some additional files, so I added a fixtures folder to contain them. Hope that works for you and happy to change if it doesn't!

@kalinchernev kalinchernev merged commit 42c0915 into Surnet:master Nov 28, 2020
@kalinchernev
Copy link
Contributor

@evans thank you!

@evans evans deleted the patch-1 branch November 29, 2020 21:39
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.

2 participants