Skip to content

Add new codepen embed script url public.codepenassets.com #159

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

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
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
Next Next commit
Refactor codepen embed code tests
  • Loading branch information
P-SiZK committed Jan 22, 2025
commit 34b43c2f9e132183813e40da59fe0f9686b02d5a
67 changes: 24 additions & 43 deletions spec/qiita/markdown/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1406,52 +1406,33 @@
end

shared_examples_for "override embed code attributes" do |allowed:|
context "with HTML embed code for CodePen using old script url" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
MARKDOWN
end

if allowed
it "does not sanitize embed code" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
HTML
end
else
it "forces async attribute on script" do
should eq <<-HTML.strip_heredoc
[
"https://production-assets.codepen.io/assets/embed/ei.js",
"https://static.codepen.io/assets/embed/ei.js",
"https://cpwebassets.codepen.io/assets/embed/ei.js",
].each do |script_url|
context "with HTML embed code for CodePen using script url `#{script_url}`" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://production-assets.codepen.io/assets/embed/ei.js" async="async"></script>
HTML
<script src="#{script_url}"></script>
MARKDOWN
end
end
end

context "with HTML embed code for CodePen" do
let(:markdown) do
<<-MARKDOWN.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://static.codepen.io/assets/embed/ei.js"></script>
MARKDOWN
end

if allowed
it "does not sanitize embed code" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://static.codepen.io/assets/embed/ei.js"></script>
HTML
end
else
it "forces async attribute on script" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="https://static.codepen.io/assets/embed/ei.js" async="async"></script>
HTML
if allowed
it "does not sanitize embed code" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="#{script_url}"></script>
HTML
end
else
it "forces async attribute on script" do
should eq <<-HTML.strip_heredoc
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
<script src="#{script_url}" async="async"></script>
HTML
end
end
end
end
Expand Down