Skip to content

Fix incomplete string escaping or encoding #1399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ptrgits
Copy link

@ptrgits ptrgits 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

@ptrgits ptrgits requested a deployment to fork-preview-protection August 8, 2025 06:44 — with GitHub Actions Waiting
@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