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

[utils] Simplify check isRegExp #430

Closed
wants to merge 1 commit into from

Conversation

Connormiha
Copy link
Contributor

I refactored isRegExp to use short method for checking.

@codecov
Copy link

codecov bot commented Jan 20, 2022

Codecov Report

Merging #430 (cf9622e) into main (408ff95) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #430   +/-   ##
=======================================
  Coverage   99.85%   99.85%           
=======================================
  Files           8        8           
  Lines        1408     1424   +16     
  Branches      172      173    +1     
=======================================
+ Hits         1406     1422   +16     
  Misses          2        2           
Impacted Files Coverage Δ
lib/utils.js 100.00% <100.00%> (ø)
test/stringify.js 99.75% <0.00%> (-0.01%) ⬇️
lib/parse.js 100.00% <0.00%> (ø)
test/parse.js 99.79% <0.00%> (+<0.01%) ⬆️

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 408ff95...cf9622e. Read the comment docs.

@@ -212,7 +212,7 @@ var compact = function compact(value) {
};

var isRegExp = function isRegExp(obj) {
return Object.prototype.toString.call(obj) === '[object RegExp]';
return obj instanceof RegExp;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately this is not short, it's broken. instanceof doesn't work across realms, and can be easily forged.

@ljharb
Copy link
Owner

ljharb commented Jan 20, 2022

Please discuss changes like this in issues first, rather than sending a PR that might not be needed :-) all the "is" checks in this library are precisely what is needed.

@ljharb ljharb closed this Jan 20, 2022
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