Skip to content

Loading…

Fix `PxLoaderTags#contains` always returning true when comparing tag arrays with only one element #15

Merged
merged 1 commit into from

2 participants

@leolannenmaki

The problem is:

new PxLoaderTags('tag').contains(new PxLoaderTags('tag2')) ==> false
new PxLoaderTags(['tag1']).contains(new PxLoaderTags(['tag2'])) ==> true

This happens because contains checks if the length of both arrays is one and
if this is the case it tries to compare the supposed singular value from both.
This then results in comparing null against null and then returning true, incorrectly.

@leolannenmaki leolannenmaki Fix `PxLoaderTags#contains` when comparing tag arrays with one element
The problem is:
    new PxLoaderTags('tag').contains(new PxLoaderTags('tag2')) ==> false
    new PxLoaderTags(['tag1']).contains(new PxLoaderTags(['tag2'])) ==> true

This happens because `contains` checks if the length of both arrays is one and
if this is the case it tries to compare the supposed singular value from both.
This then results in comparing null against null and then returning true, incorrectly.
73628dc
@joelfillmore joelfillmore merged commit b014ce5 into thinkpixellab:master
@joelfillmore
Pixel Lab member

@leolannenmaki - thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 30, 2012
  1. @leolannenmaki

    Fix `PxLoaderTags#contains` when comparing tag arrays with one element

    leolannenmaki committed
    The problem is:
        new PxLoaderTags('tag').contains(new PxLoaderTags('tag2')) ==> false
        new PxLoaderTags(['tag1']).contains(new PxLoaderTags(['tag2'])) ==> true
    
    This happens because `contains` checks if the length of both arrays is one and
    if this is the case it tries to compare the supposed singular value from both.
    This then results in comparing null against null and then returning true, incorrectly.
Showing with 1 addition and 1 deletion.
  1. +1 −1 PxLoader.js
View
2 PxLoader.js
@@ -349,7 +349,7 @@ function PxLoaderTags(values) {
this.contains = function(other) {
if (this.length === 0 || other.length === 0) {
return false;
- } else if (this.length === 1) {
+ } else if (this.length === 1 && this.value !== null) {
if (other.length === 1) {
return this.value === other.value;
} else {
Something went wrong with that request. Please try again.