Skip to content

map renders an error when it shouldn't. #647

@ebobby

Description

@ebobby

Calling map with an array of objects where one of the objects doesn't have the given key, when strictVariables: true ends up in a weird interaction because of the call to _getFromScope.

Ruby simply returns nothing for those cases, liquidjs is instead rendering the error instead of throwing it.

    it('should not throw or render an error', function () {
      const posts = [{ category: 'foo' }, { name: 'bar' }]
      return test('{{posts | map: "category"}}', { posts }, 'foo', { strictVariables: true })
    })

This test results in:

  ● filters/array › map › should not throw or render an error

    expect(received).toBe(expected) // Object.is equality

    Expected: "foo"
    Received: "InternalUndefinedVariableError: undefined variable: category"

Notice how the error is rendered into the output string, and not even thrown. Ruby doesn't throw though, with strict vars and strict filiters it simply doesn't return anything. Yo would get "foo" as output for the given test.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions