Skip to content

Unexpected output when using curly braces in arrays in jbuilder files #608

@asbjorn-brevio

Description

@asbjorn-brevio

It seems like there's a (major) difference between using { } syntax and do end syntax in jbuilder files, but I haven't found any information about this in the readme or existing issues. I'm not that experienced with Rails so this could very well be an issue of weird configs for all I know, but given the potential impact I thought it was better to report in case it is a real issue. Assuming that there's no weirdness going on only in my app, it seems like it would be a good idea to handle or at least document this.

Reproduction steps:
Use the single-line block syntax with curly braces for an array, f ex json.users @users { |user| json.(user, :id) }

Expected behavior:
Like for json.users @users do json.(user, :id) end the output is a list of hashes, each with an id property. (Or alternatively some error that explains that the curly syntax shouldn't be used)

Actual behavior:
A list of hashes, each with a ton of properties. It looks suspiciously like the output of .attributes. In my case I've now exposed things like the password hashes of users without realizing it. It seems like the entire block is ignored if the curly syntax is used. F ex json.users @users do raise "error" end raises, but json.users @users { raise "error" } does not.

Versions:
Ruby: 3.4.2
Rails: 8.0.2
Jbuilder: 2.13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions