ankane/chartkick · error · ArgumentError
Invalid #{k}
Error message
Invalid #{k} What it means
Error "Invalid #{k}" thrown in ankane/chartkick.
Source
Thrown at lib/chartkick/helper.rb:81
nonce = nil
end
end
nonce_html = nonce ? " nonce=\"#{ERB::Util.html_escape(nonce)}\"" : nil
# html vars
html_vars = {
id: element_id,
height: height,
width: width,
# don't delete loading option since it needs to be passed to JS
loading: options[:loading] || "Loading..."
}
[:height, :width].each do |k|
# limit to alphanumeric and % for simplicity
# this prevents things like calc() but safety is the priority
# dot does not need escaped in square brackets
raise ArgumentError, "Invalid #{k}" unless /\A[a-zA-Z0-9%.]*\z/.match?(html_vars[k])
end
html_vars.each_key do |k|
# escape all variables
# we already limit height and width above, but escape for safety as fail-safe
# to prevent XSS injection in worse-case scenario
html_vars[k] = ERB::Util.html_escape(html_vars[k])
end
html = (options.delete(:html) || %(<div id="%{id}" style="height: %{height}; width: %{width}; text-align: center; color: #999; line-height: %{height}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">%{loading}</div>)) % html_vars
# js vars
js_vars = {
type: klass.to_json,
id: element_id.to_json,
data: data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json,
options: options.to_json
}View on GitHub (pinned to 2c6cd4eb62)
When it happens
Trigger: Thrown at lib/chartkick/helper.rb:81 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ankane/chartkick@2c6cd4eb62 (2026-08-21).
Data as JSON: /api/errors/ac91be27ad53c14e.
Report an issue: GitHub.