diff options
| author | Earlopain <14981592+Earlopain@users.noreply.github.com> | 2026-02-02 12:59:09 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-02-02 18:26:20 +0000 |
| commit | 30d2e0cd6b94752e939025e2d5751f4b24e601ff (patch) | |
| tree | accdb18931590a70e370347a74f8f684db9e8a7c | |
| parent | 997943219c2d44e60d1d7ae25c8f78c99ce6d970 (diff) | |
[ruby/prism] Add escaping for doxygen token comment
Many characters have special meaning and break formatting
https://github.com/ruby/prism/commit/0b9d516c26
| -rw-r--r-- | prism/templates/include/prism/ast.h.erb | 2 | ||||
| -rwxr-xr-x | prism/templates/template.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/prism/templates/include/prism/ast.h.erb b/prism/templates/include/prism/ast.h.erb index 9115f20eaa..0612341772 100644 --- a/prism/templates/include/prism/ast.h.erb +++ b/prism/templates/include/prism/ast.h.erb @@ -22,7 +22,7 @@ */ typedef enum pm_token_type { <%- tokens.each do |token| -%> - /** <%= token.comment %> */ + /** <%= Prism::Template::Doxygen.verbatim(token.comment) %> */ PM_TOKEN_<%= token.name %><%= " = #{token.value}" if token.value %>, <%- end -%> diff --git a/prism/templates/template.rb b/prism/templates/template.rb index 6c3efd7e6c..aca626b5eb 100755 --- a/prism/templates/template.rb +++ b/prism/templates/template.rb @@ -49,6 +49,14 @@ module Prism end end + # This module contains methods for escaping characters in Doxygen comments. + module Doxygen + # Similar to /verbatim ... /endverbatim but doesn't wrap the result in a code block. + def self.verbatim(value) + value.gsub(/[\.*%!`#<>_+-]/, '\\\\\0') + end + end + # A comment attached to a field or node. class ConfigComment attr_reader :value |
