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

twig.contains works wrong #86

Open
apsavin opened this issue Oct 9, 2014 · 0 comments
Open

twig.contains works wrong #86

apsavin opened this issue Oct 9, 2014 · 0 comments
Labels

Comments

@apsavin
Copy link

apsavin commented Oct 9, 2014

If we have in file.twig code like this:

{% set myVar = '1' %}
{% set myArray = [1, 2] %}
{% if myVar in myArray %} 1 {% else %} 2 {% endif %}

then result is '1' with php
but '2' with js.
It's so, because the way how twig.contains works:

$goog$exportSymbol$$("twig.contains", function($haystack$$, $needle$$) {
        var $JSCompiler_temp$$159_JSCompiler_temp$$160_key$$inline_169$$;
        if($goog$isArray$$($haystack$$)) {
// incorrect way, strict eq (through indexOf)
            $JSCompiler_temp$$159_JSCompiler_temp$$160_key$$inline_169$$ = 0 <= $goog$array$indexOf$$($haystack$$, $needle$$)
        }else {
            if($goog$isString$$($haystack$$)) {
                $JSCompiler_temp$$159_JSCompiler_temp$$160_key$$inline_169$$ = -1 != $haystack$$.indexOf($needle$$) && ("" !== $needle$$ || "" === $haystack$$)
            }else {
                a: {
                    for($JSCompiler_temp$$159_JSCompiler_temp$$160_key$$inline_169$$ in $haystack$$) {
// correct way, non-strict eq '=='
                        if($haystack$$[$JSCompiler_temp$$159_JSCompiler_temp$$160_key$$inline_169$$] == $needle$$) {
                            $JSCompiler_temp$$159_JSCompiler_temp$$160_key$$inline_169$$ = $JSCompiler_alias_TRUE$$;
                            break a
                        }
                    }
                    $JSCompiler_temp$$159_JSCompiler_temp$$160_key$$inline_169$$ = $JSCompiler_alias_FALSE$$
                }
            }
        }
        return $JSCompiler_temp$$159_JSCompiler_temp$$160_key$$inline_169$$
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants