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 valid chars test for the property of metadata #2601

Merged
merged 3 commits into from
Sep 8, 2020

Conversation

adzo261
Copy link
Contributor

@adzo261 adzo261 commented Sep 6, 2020

Refers to issue #2595

As per our discussion, metadata.property can contain only lowercase alphanumeric characters and dashes.
PR adds a test for the same, which raises an error if metadata.property values doesn't have valid characters.

Please have a look. Thanks!

@adzo261 adzo261 changed the title Add lowercase test for the property of metadata #2595 Add lowercase test for the property of metadata Sep 6, 2020
@codecov
Copy link

codecov bot commented Sep 6, 2020

Codecov Report

Merging #2601 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2601      +/-   ##
==========================================
+ Coverage   95.15%   95.18%   +0.02%     
==========================================
  Files           5        5              
  Lines         165      166       +1     
==========================================
+ Hits          157      158       +1     
  Misses          8        8              
Impacted Files Coverage Δ
lib/metadata.js 100.00% <100.00%> (ø)

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 bd06d5a...78c9fd4. Read the comment docs.

lib/metadata.js Outdated
Comment on lines 88 to 90
const properties = Array.isArray(metadata.property) ? metadata.property : [metadata.property];
properties.forEach(function (property) {
if (property.match(/[A-Z]/)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 I was wondering why you used a forEach to analyze the properties. Each file is already checked separately thanks to line 11. I think that we would only need current lines 90 to 92 to do the task in this case (+ in that way we have a much cleaner output error)

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, just as we are here I've seen in the other file that in the test you included _, maybe we could throw spaces and _ to the Regex (as we really don't use them either). Take into account that we would need to change the error message to something like Property includes invalid characters

Copy link
Contributor

Choose a reason for hiding this comment

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

But for the rest, really good work Aditya!! 💪. Thank you very much :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for reviewing and commenting.
I found that metadata.property was an array of strings in somecases.
And in other cases it was a normal string.
Hence, I had to add a check for array and run a loop over it.

And do we need to check symbols(non-alphanumeric) also? I can add that check too if we want it. And then we can change the error to more generic as you said.

Copy link
Contributor

Choose a reason for hiding this comment

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

I found that metadata.property was an array of strings ...

Ah okay, I didn't think about that. Very clever! In that case that part is perfect.

And do we need to check symbols(non-alphanumeric) also?

It would be nice to test for symbols too (except the dash - as we use kebab-case for properties). If you include dots take care, I don't think so, but maybe subproperties (like in the clipboard test) give you errors.

Thank you for reviewing and commenting.

Thanks to you for working on the PR :)

Copy link
Contributor Author

@adzo261 adzo261 Sep 7, 2020

Choose a reason for hiding this comment

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

From what I could understand, metadata.property can have only lowercase alphanumeric characters and a special symbol - for kebab-case.
Can you once confirm the set of symbols we can have?

And also does - "Property can have only lowercase alphanumeric characters and kebab symbol" makes sense as an error message then?

Post confirmation, I will start working on it.

Copy link
Contributor

@Markel Markel Sep 7, 2020

Choose a reason for hiding this comment

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

Yep, if I'm not mistaken only lowercase letters and dashes are allowed.

About the error message, maybe is more clear if it says dashes instead of kebab symbols.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the PR. We can have a second round of review.

@adzo261 adzo261 changed the title Add lowercase test for the property of metadata Add valid chars test for the property of metadata Sep 7, 2020
Copy link
Contributor

@Markel Markel left a comment

Choose a reason for hiding this comment

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

Looks okay to me, I specially like how you dealt with the regex there :) If I had to nitpick maybe I would move line 95 to 86 (to keep the polyfill test along). But for me this is an approval 🎉

What do you think @rejas ??

@rejas
Copy link
Member

rejas commented Sep 8, 2020

Looks good. Nice work @adzo261

@rejas rejas merged commit 3ccc7f1 into Modernizr:master Sep 8, 2020
@rejas rejas added this to the Modernizr v4.0 milestone Sep 8, 2020
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.

3 participants