10BC0 Strict locals parsing fails with HAML partials and multiple comments merged into one line · Issue #56646 · rails/rails · GitHub
[go: up one dir, main page]

Skip to content

Strict locals parsing fails with HAML partials and multiple comments merged into one line #56646

@fabian-as

Description

@fabian-as

Steps to reproduce

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "rails"
  # If you want to test against edge Rails replace the previous line with this:
  # gem "rails", github: "rails/rails", branch: "main"
  gem "haml"
end

require "action_controller/railtie"
require "action_view/railtie"
require "minitest/autorun"

class TestApp < Rails::Application
  config.load_defaults Rails::VERSION::STRING.to_f
  config.eager_load = false
  config.logger = Logger.new($stdout)
  config.secret_key_base = "secret_key_base"
end
Rails.application.initialize!

class BugTest < ActionView::TestCase
  setup do
    @view_path = Pathname.new(Dir.mktmpdir)
    ActionController::Base.prepend_view_path @view_path
  end

  teardown do
    @view_path.rmtree
  end

  def test_action_view_render_template
    view_file "posts/index.html.haml", <<~HAML
      %h1 Posts

      - posts.each do |post|
        = render partial: "posts/post", locals: { post: post }
    HAML

    view_file "posts/_post.html.haml", <<~HAML
      -# locals: (post:), haml-lint:disable LineLength
      %p= upcase(post)
    HAML

    render template: "posts/index", locals: { posts: ["hello world"] }

    assert_equal "hello world", rendered.html.at("p").text
  end

  private
  def view_file(filename, contents)
    pathname = @view_path.join(filename)
    pathname.dirname.mkpath
    pathname.write(contents.chomp)
  end
end

Expected behavior

The partial should be rendered as before. The bug was likely introduced with #56270. The example will work fine with Rails 8.0.x

Actual behavior

An ActionView::SyntaxErrorInTemplate exception is thrown.

System configuration

Rails version: 8.1.2

Ruby version: 4.0.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

      0