Project

General

Profile

Actions

Defect #44703

open

Tests using a Regexp with :match in assert_select fail with Nokogiri 1.19.5 and later

Added by Go MAEDA about 12 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Gems support
Target version:
-
Resolution:
Affected version:

Description

After updating Nokogiri from 1.19.4 to 1.19.5 or later, the following seven tests fail:

  • IssuesControllerTest#test_show_should_link_attachments_to_the_journal_that_added_them
  • IssuesControllerTest#test_show_should_display_attachment_icons_by_mime_type
  • IssuesControllerTest#test_get_edit_for_issue_with_transition_warning_should_show_the_warning
  • LayoutTest#test_wiki_formatter_header_tags
  • ThemesTest#test_application_css
  • ThemesTest#test_use_default_favicon_if_theme_provides_none
  • ThemesTest#test_with_sub_uri
Failure:
IssuesControllerTest#test_show_should_link_attachments_to_the_journal_that_added_them [test/functional/issues_controller_test.rb:2355]:
Expected at least 1 element matching "svg.icon-svg use:match('href', /assets\\/icons-\\w+.svg#icon--chevrons-down/)", found 0.
Expected 0 to be >= 1.

The HTML rendered by Redmine is correct. All of these tests pass a Regexp containing backslash escapes, such as \w, to the :match pseudo-class.

Cause

When a Regexp is passed to :match, assert_select embeds its source in the CSS selector as a quoted string. Nokogiri 1.19.5 appears to have changed how backslashes in CSS strings are interpreted. They are now treated as escape characters, so \w becomes w before the value is matched, and the pattern no longer matches digested asset paths such as /assets/icons-dcd4c308.svg.

For example, Nokogiri::CSS.xpath_for('a:match("href", "icons-\w+")') returns:

Nokogiri 1.19.4: //a[nokogiri:match(.,"href","icons-\w+")]
Nokogiri 1.19.5: //a[nokogiri:match(.,'href','icons-w+')]

Proposed fix

The attached patch rewrites the regular expressions so that they contain no backslashes:

  • \w+ is replaced with [0-9a-f]+, because Propshaft digests are hexadecimal.
  • %r{...} is used so that / does not need to be escaped.
  • \. is replaced with .. This makes the patterns in ThemesTest slightly less strict, but the patterns in IssuesControllerTest and LayoutTest already used an unescaped ..

The patch changes test code only. With the patch applied, all of the tests listed above pass with Nokogiri 1.19.6.


Files

No data to display

Actions

Also available in: Atom PDF