Skip to content
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

excape HTML entities (<>&") in HTML and Markdown output #377

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bin/kafo-export-params
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require 'kafo/parser_cache_writer'
require 'kafo/string_helper'
require 'logger'
require 'yaml'
require 'cgi'

KafoConfigure = OpenStruct.new
def KafoConfigure.exit(code)
Expand Down Expand Up @@ -76,9 +77,10 @@ module Kafo

@config.modules.sort.each do |mod|
mod.params.sort.each do |param|
html_doc = CGI.escapeHTML(param.doc.join(' '))
puts ' <tr>'
puts " <td style='white-space:nowrap'>#{parametrize(param)}</td>"
puts " <td>#{param.doc.join(' ')}</td>"
puts " <td>#{html_doc}</td>"
puts ' </tr>'
end
end
Expand Down Expand Up @@ -129,7 +131,8 @@ module Kafo
puts "| #{'-'*40} | #{'-' * @max} |"
@config.modules.sort.each do |mod|
mod.params.sort.each do |param|
puts "| #{parametrize(param).ljust(40)} | #{param.doc.join(' ').ljust(@max)} |"
html_doc = CGI.escapeHTML(param.doc.join(' '))
puts "| #{parametrize(param).ljust(40)} | #{html_doc.ljust(@max)} |"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/acceptance/kafo_export_params_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module Kafo
it 'must output markdown' do
_(command[1]).must_match(/\| Parameter name\s*\| Description\s*\|/)
_(command[1]).must_match(/\| --testing-db-type\s*\| can be mysql or sqlite\s*\|/)
_(command[1]).must_include '&lt;List of IPs&gt;'
end
end

Expand All @@ -52,6 +53,7 @@ module Kafo
_(command[1]).must_include '<th>Option</th>'
_(command[1]).must_match %r{<td.*>--testing-db-type</td>}
_(command[1]).must_include '<td>can be mysql or sqlite</td>'
_(command[1]).must_include '&lt;List of IPs&gt;'
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/manifests/basic.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
# consisting of 3 lines
# $typed:: something having it's type explicitly set
# $multivalue:: list of users
# $complex_variant:: A Variant type that can be:
# String with:
# '' or 'unmanaged' - Host auth control done elsewhere
# 'ip <List of IPs>' - Allowed IPs/ranges
# Array of strings with ip or host as above
Comment on lines +14 to +18
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably can cut this down to a more artificial doc string.
Currently it very much mimics what's in https://github.com/puppetlabs/puppetlabs-apache/blob/main/manifests/mod/status.pp (and breaking our doc builds)

# === Advanced parameters
#
# $debug:: we have advanced parameter, yay!
Expand Down Expand Up @@ -43,6 +48,7 @@
$username = 'root',
Sensitive[String[1]] $password = Sensitive('supersecret'),
Integer $pool_size = 10,
Optional[Variant[String, Array]] $complex_variant = undef,
$file = undef,
$base_dir = undef) {

Expand Down
Loading