Skip to content

Performance/StringIdentifierArgument autocorrect broke nokogiri parsing of html #278

@ShockwaveNN

Description

@ShockwaveNN

Steps to reproduce the problem

  1. Create file with code code.rb:
# frozen_string_literal: true

require 'nokogiri'

html_doc = Nokogiri::HTML("<html data='value'><body><h1>Mr. Belvedere Fan Club</h1></body></html>")
puts html_doc.xpath('//html').attr('data')

and .rubocop.yml:

require:
  - rubocop-performance

AllCops:
  NewCops: enable
  1. run it - it will return value:
$ ruby code.rb 
value
  1. rubocop -A:
rubocop -A
Inspecting 1 file
C

Offenses:

code.rb:6:36: C: [Corrected] Performance/StringIdentifierArgument: Use :data instead of 'data'.
puts html_doc.xpath('//html').attr('data')
                                   ^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
  1. run file - it will fail
.rvm/gems/ruby-3.0.3/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/xml/node_set.rb:209:in `attribute': no implicit conversion of Symbol into String (TypeError)

RuboCop version

$ [bundle exec] rubocop -V
1.24.0 (using Parser 3.0.3.2, rubocop-ast 1.15.0, running on ruby 3.0.3 x86_64-linux)
  - rubocop-performance 1.13.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions