[deploy] Allow glitch id starting with ~ (#10544)
This commit is contained in:
parent
749dd55d41
commit
ee989a0d47
2 changed files with 9 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ class GlitchTag < LiquidTagBase
|
|||
|
||||
PARTIAL = "liquids/glitch".freeze
|
||||
ID_REGEXP = /\A[a-zA-Z0-9\-]{1,110}\z/.freeze
|
||||
TILDE_PREFIX_REGEXP = /\A~/.freeze
|
||||
OPTION_REGEXP = /(app|code|no-files|preview-first|no-attribution|file=\w(\.\w)?)/.freeze
|
||||
OPTIONS_TO_QUERY_PAIR = {
|
||||
"app" => %w[previewSize 100],
|
||||
|
|
@ -36,6 +37,7 @@ class GlitchTag < LiquidTagBase
|
|||
|
||||
def parse_id(input)
|
||||
id = input.split(" ").first
|
||||
id.sub!(TILDE_PREFIX_REGEXP, "")
|
||||
raise StandardError, "Invalid Glitch ID" unless valid_id?(id)
|
||||
|
||||
id
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ RSpec.describe GlitchTag, type: :liquid_tag do
|
|||
let(:id_with_file_option) { "some-id file=script.js" }
|
||||
let(:id_with_app_and_code_option) { "some-id app code" }
|
||||
let(:id_with_many_options) { "some-id app no-attribution no-files file=script.js" }
|
||||
let(:id_starting_with_tilde) { "~some-id" }
|
||||
|
||||
def generate_tag(id)
|
||||
Liquid::Template.register_tag("glitch", GlitchTag)
|
||||
|
|
@ -76,5 +77,11 @@ RSpec.describe GlitchTag, type: :liquid_tag do
|
|||
expected = "src=\"#{base_uri}some-id?path=index.html"
|
||||
expect(template.render(nil)).to include(expected)
|
||||
end
|
||||
|
||||
it "removes the tilde prefix of ids" do
|
||||
template = generate_tag(id_starting_with_tilde)
|
||||
expected = "src=\"#{base_uri}some-id?path=index.html"
|
||||
expect(template.render(nil)).to include(expected)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue