Skip to content

Conversation

@kreeksec
Copy link

@kreeksec kreeksec commented Aug 8, 2025

fix the problem, replace text.sub('\\', '') with text.gsub('\\', '') so that all occurrences of the backslash character are removed from the string, not just the first one. This change should be made only on line 297 in the handle_regexp_SUPPRESSED_CROSSREF method in lib/rdoc/markup/to_rdoc.rb. No additional imports or method definitions are required, as gsub is a standard Ruby String method. This change preserves the intended functionality while ensuring that all backslashes are removed, not just the first.

References

RailsActiveRecord::Base::sanitize_sql

@kreeksec kreeksec had a problem deploying to fork-preview-protection August 8, 2025 06:44 — with GitHub Actions Failure
@kou kou changed the title Fix Incomplete string escaping or encoding Fix incomplete string escaping or encoding Aug 8, 2025
@kou
Copy link
Member

kou commented Aug 8, 2025

Could you also share an input that reproduces this problem and the actual result and expected result with the input?

It seems that RailsActiveRecord::Base::sanitize_sql https://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html#method-i-sanitize_sql doesn't use backslack.

@tompng
Copy link
Member

tompng commented Aug 9, 2025

This part is registered on line 59

@markup.add_regexp_handling(/\\\S/, :SUPPRESSED_CROSSREF)

A string that matches /\\\S/ (two length string starts with ) is passed to handle_regexp_SUPPRESSED_CROSSREF.

Example rdoc format:

== See \RDoc and \Array and \Hash. Use backslash(\\)

Example target passed to handle_regexp_SUPPRESSED_CROSSREF: "\\R", "\\A", "\\H", "\\\\"

Expected output:

== See RDoc and Array and Hash. Use backslash(\)

target is always two-length string that starts with \ and only the first backslash should be removed. If second char is \, it should remain.
text.sub is enough. text.gsub will wrongly removes escaped backslashes.

@tompng tompng closed this Aug 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants