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

Fix 'duplicate types' check for properties with a single type #1399

Merged
merged 1 commit into from
Jan 6, 2020

Conversation

hanzi
Copy link
Member

@hanzi hanzi commented Jan 5, 2020

fixes #1263

The 'duplicate types' check would fail if properties with single-value TYPE parameters were present,

Background

prop.getParameter('type') would return an Array if multiple types are present, but a String if there's only one type:

TEL;TYPE="HOME,VOICE":+12345

Here, prop is going to be [ 'HOME', 'VOICE' ]. This works.

EMAIL;TYPE=HOME:john.doe@example.com

Whereas here, prop will end up as just 'HOME'. If you pass a string into new Set(), it will create an array containing all the individual characters of the string. So the check ends up effectively doing:

[ [ 'home' ] ].join('') === [ [ 'h', 'o', 'm', 'e' ] ].join('')
// returns false, because 'home' !== 'h,o,m,e'

This is fixed by moving the Array.isArray check into the filter call, so that only properties with multiple types are compared to begin with.

I removed some other checks that were unnecessary: Array.filter and Array.map always return an array, so props is already guaranteed to be one, and there's no harm in comparing empty arrays.

Signed-off-by: Christian Kraus <hanzi@hanzi.cc>
@codecov
Copy link

codecov bot commented Jan 5, 2020

Codecov Report

Merging #1399 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1399   +/-   ##
=======================================
  Coverage   62.31%   62.31%           
=======================================
  Files           4        4           
  Lines          69       69           
=======================================
  Hits           43       43           
  Misses         26       26

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 4d3c86d...f8435e9. Read the comment docs.

@skjnldsv skjnldsv merged commit df8c466 into nextcloud:master Jan 6, 2020
@welcome
Copy link

welcome bot commented Jan 6, 2020

Thanks for your first pull request and welcome to the community! Feel free to keep them coming! If you are looking for issues to tackle then have a look at this selection: https://github.com/nextcloud/contacts/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22
Most developers hang out on IRC. So join #nextcloud-contacts and #nextcloud-dev on Freenode for a chat!

@skjnldsv skjnldsv added 3. to review Waiting for reviews bug Something isn't working labels Jan 6, 2020
@hanzi hanzi deleted the fix-duplicate-types-check branch January 6, 2020 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new created contact shows warning in console that a correction has failed
2 participants