Skip to content

Invalid syntax in assign tag should throw syntax error #229

Closed

Description

@fw42

Similar to #225, some tags don't raise SyntaxError's but just silently do whatever they want.

{% assign foo = 1 + 2 %} is another example of that.

We should really be more strict here.

cc @trishume

Activity

  1. trishume commented on Jul 23, 2013

    @trishume
    Contributor

    This occurs anywhere that Liquid::Variable is used.

    [9] pry(main)> s = "{{lol + 1}}"
    => "{{lol + 1}}"
    [10] pry(main)> Liquid::Template.parse(s).render('lol' => 5)
    => "5"
  2. trishume commented on Jul 24, 2013

    @trishume
    Contributor

    In related news:

    [12] pry(main)> t = Liquid::Template.parse("{{h + 1 |:::| filter, hi|,|,,:,,|l||}}")
    => #<Liquid::Template:0x007fc25c11fdc0
     @resource_limits={},
     @root=
      #<Liquid::Document:0x007fc25c11fc80
       @blank=false,
       @nodelist=
        [#<Liquid::Variable:0x007fc25c11fb40
          @filters=[["filter", ["hi"]], ["l", []]],
          @markup="h + 1 |:::| filter, hi|,|,,:,,|l||",
          @name="h">]>>

    ⚠️

  3. fw42 commented on Jul 24, 2013

    @fw42
    ContributorAuthor

    💩

  4. fw42 commented on Jul 24, 2013

    @fw42
    ContributorAuthor

    Is this only happening when parsing variables?

  5. trishume commented on Jul 24, 2013

    @trishume
    Contributor

    Basically there is no uniformity whatsoever when it comes to parsing. Every tag just throws regexes at it.
    So some tags have robust parsers with error messages, and others like variable tags don't throw syntax errors ever.
    It is actually impossible to make a variable tag throw a syntax error:

    [23] pry(main)> t = Liquid::Template.parse("{{---E(R[\'\"\'\"\'(+=EH%*^(@#^%$)?||?\eE,PUZE:::~~~~``}}")
    => #<Liquid::Template:0x007fc25d354860
     @resource_limits={},
     @root=
      #<Liquid::Document:0x007fc25d354748
       @blank=false,
       @nodelist=
        [#<Liquid::Variable:0x007fc25d354608
          @filters=[["E", ["PUZE:::~~~~``"]]],
          @markup="---E(R['\"'\"'(+=EH%*^(@#^%$)?||?\eE,PUZE:::~~~~``",
          @name="---E(R['\"'">]>>
  6. trishume commented on Jul 25, 2013

    @trishume
    Contributor

    Darn it. I wanted not to modify the existing test suite but the suite has tests that assert that the parsing is crap.

    Like the stupid argument separators here:

    def test_lax_filter_argument_parsing
      var = Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
      assert_equal 'number_of_comments', var.name
      assert_equal [['pluralize',["'comment'","'comments'"]]], var.filters
    end

    and the not using quotation marks here:

    def test_symbol
      var = Variable.new("http://disney.com/logo.gif | image: 'med' ")
      assert_equal 'http://disney.com/logo.gif', var.name
      assert_equal [["image",["'med'"]]], var.filters
    end
  7. fw42 commented on Jul 25, 2013

    @fw42
    ContributorAuthor

    imho, we should just break them and fix the shitty templates afterwards instead of forcing ourselves to keep this crappy parsing.

  8. trishume commented on Jul 25, 2013

    @trishume
    Contributor

    What should we break:

    • Arbitrary text in variables without quotes ({{http://disney.com/logo.gif}})
    • Empty Filters ({{hi|||}})
    • Bad filter separators ({{number_of_comments | pluralize: 'comment': 'comments'}})

    Breaking these would probably need a major version bump, but I think it is worth it since they are all pretty wtf.

  9. fw42 commented on Jul 25, 2013

    @fw42
    ContributorAuthor

    Yeah we can do that for Liquid 3.0, and add some logging in Shopify for 2.6 to find out what we will need to fix.

  10. trishume commented on Jul 25, 2013

    @trishume
    Contributor

    Deprecation warnings ftw!

  11. trishume commented on Jul 25, 2013

    @trishume
    Contributor

    Darn, my new parser has a negative effect on the benchmark. Time to get out the profiler!

    Old:

    Rehearsal ------------------------------------------------
    parse:         3.430000   0.050000   3.480000 (  3.477676)
    parse & run:   8.080000   0.060000   8.140000 (  8.135299)
    -------------------------------------- total: 11.620000sec
    
                       user     system      total        real
    parse:         3.660000   0.030000   3.690000 (  3.809591)
    parse & run:   7.990000   0.040000   8.030000 (  8.037614)
    

    New:

    Rehearsal ------------------------------------------------
    parse:         4.670000   0.050000   4.720000 (  4.715765)
    parse & run:  10.070000   0.040000  10.110000 ( 10.207468)
    -------------------------------------- total: 14.830000sec
    
                       user     system      total        real
    parse:         4.710000   0.020000   4.730000 (  4.840936)
    parse & run:  10.060000   0.030000  10.090000 ( 10.194240)
    
  12. trishume commented on Jul 25, 2013

    @trishume
    Contributor

    @fw42 I have an idea for how to implement the deprecation warnings so they catch all cases.
    We can include the new parser in Liquid 2.6 but just have all syntax errors be output as deprecation warnings and then fall back on the old parser.

    It will take the performance hit of parsing twice but only for tags with broken syntax.

  13. ghost assigned on Aug 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions