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

🐛 Fix value_regex for amp-tiktok@data-src to allow repeating digits and a TikTok URL #35329

Merged
merged 5 commits into from Aug 3, 2021

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Jul 21, 2021

This fixes a typo introduced in #33999, where the value_regex for data-src was specified to allow only a single digit whereas it should instead allow any number of digits. It's also supposed to allow a TikTok URL as seen here:

<!-- Valid -->
<amp-tiktok width="500" height="500" data-src="6943753342808034566">
</amp-tiktok>
<!-- Valid -->
<amp-tiktok
width="700"
height="800"
data-src="https://www.tiktok.com/@scout2015/video/6943753342808034566">
</amp-tiktok>

Neither of these examples are currently valid, although they both properly construct as seen in the AMP Playground.

Originally discovered by @pierlon in ampproject/amp-wp#6436 (comment).

Closes #35514.

@amp-owners-bot
Copy link

amp-owners-bot bot commented Jul 21, 2021

Hey @ampproject/wg-caching! These files were changed:

extensions/amp-tiktok/0.1/test/validator-amp-tiktok.out
extensions/amp-tiktok/validator-amp-tiktok.protoascii

@westonruter
Copy link
Member Author

westonruter commented Jul 21, 2021

I'm missing something here, namely that data-src is also supposed to be a URL:

<!-- Valid -->
<amp-tiktok
width="700"
height="800"
data-src="https://www.tiktok.com/@scout2015/video/6943753342808034566">
</amp-tiktok>

This isn't valid in the validator now either, although the component initializes properly.

UPDATE: This is fixed in ad667c7, although it doesn't constrain that the value is actually a valid TikTok URL.

@westonruter westonruter changed the title 🐛 Fix value_regex for amp-tiktok@data-src to allow repeating digits 🐛 Fix value_regex for amp-tiktok@data-src to allow repeating digits and a URL Jul 21, 2021
@@ -32,7 +32,7 @@ tags: { # <amp-tiktok>
attr_lists: "extended-amp-global"
attrs: {
name: "data-src";
value_regex: "\\d";
value_regex: "(.+/)?\\d+/?";
Copy link
Member Author

Choose a reason for hiding this comment

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

It would seem that a value_url would be better for the case of a TikTok URL value, but given that the amp-tiktok component is only parsing the ID out of the URL, this doesn't seem required.

// If the user provides a src attribute extract the video id from the src
const videoIdRegex = /^((.+\/)?)(\d+)\/?$/;
this.videoId_ = src.replace(videoIdRegex, '$3');

Copy link
Contributor

@honeybadgerdontcare honeybadgerdontcare left a comment

Choose a reason for hiding this comment

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

lgtm after nit below

@westonruter westonruter enabled auto-merge (squash) July 23, 2021 18:29
@westonruter westonruter changed the title 🐛 Fix value_regex for amp-tiktok@data-src to allow repeating digits and a URL 🐛 Fix value_regex for amp-tiktok@data-src to allow repeating digits and a TikTok URL Jul 23, 2021
westonruter added a commit to ampproject/amp-wp that referenced this pull request Jul 23, 2021
@westonruter
Copy link
Member Author

The validator test is failing but I don't understand why: https://app.circleci.com/pipelines/github/ampproject/amphtml/13593/workflows/b6c599af-9a71-47b9-b05c-4f77aa1837c8/jobs/222119

I've run python3 build.py --update_tests locally and confirmed the amp-tiktok/0.1/test/validator-amp-tiktok.out file is as expected. However, on CircleCI it doesn't seem to have the update to the protoascii, and it thinks that the validator-amp-tiktok.out file should include:

diff --git a/extensions/amp-tiktok/0.1/test/validator-amp-tiktok.out b/extensions/amp-tiktok/0.1/test/validator-amp-tiktok.out
index 3ba71070d..6ceca814a 100644
--- a/extensions/amp-tiktok/0.1/test/validator-amp-tiktok.out
+++ b/extensions/amp-tiktok/0.1/test/validator-amp-tiktok.out
@@ -40,6 +40,8 @@ FAIL
 |    </amp-tiktok>
 |    <!-- Valid -->
 |    <amp-tiktok
+>>   ^~~~~~~~~
+amp-tiktok/0.1/test/validator-amp-tiktok.html:41:2 Tag 'amp-tiktok' must have a minimum of 1 child tags - saw 0 child tags. (see https://amp.dev/documentation/components/amp-tiktok)
 |      width="700"
 |      height="800"
 |      data-src="https://www.tiktok.com/@scout2015/video/6943753342808034566">

For some reason the value_regex is not matching when CircleCI runs the test.

@westonruter
Copy link
Member Author

@honeybadgerdontcare Any idea what's wrong?

@rbeckthomas
Copy link
Contributor

must have a minimum of 1 child tags - saw 0 child tags.

I suspect this is being caused by an error with how I set up the blockquote child. So for the spec_name: 'AMP_TIKTOK blockquote' has a mandatory_min_num_child_tags of 1, which i think is what is triggering this error.
However it seems like this is being applied across the board, so maybe that needs to be changed?

@westonruter
Copy link
Member Author

I suspect this is being caused by an error with how I set up the blockquote child. So for the spec_name: 'AMP_TIKTOK blockquote' has a mandatory_min_num_child_tags of 1, which i think is what is triggering this error.

To me it seems that rule is fine. It's just that that spec rule is being matched because the rule with data-src is failing to match. But I don't see why.

@honeybadgerdontcare
Copy link
Contributor

I updated the regex to escape the . for the domain name. It looks like circleci is unhappy with something else though and maybe the PR needs to be rebased.

#!/bin/bash -eo pipefail
curl -sS https://raw.githubusercontent.com/ampproject/amphtml/main/.circleci/compute_merge_commit.sh | bash
bash: line 1: 404:: command not found

Exited with code exit status 127
CircleCI received exit code 127

I have introduced this change in another PR to move it forward: #35514

…tok-validation

* 'main' of github.com:ampproject/amphtml: (72 commits)
  build: run amp lint --fix to address import order of jixie (ampproject#35513)
  ✨ [amp-analytics] Add Custom Browser Event Tracker (ampproject#35193)
  babel: teach amp mode transformer about #core/mode (ampproject#35477)
  🚮 Remove experiment `amp-consent-granular-consent` (ampproject#35508)
  ♻️ Enable auto-sorting+grouping within src/ and 3p/ (ampproject#35454)
  🐛  [amp-render] fix root-element stripping from amp-render with amp-bind (ampproject#35449)
  ✅ [Story interactive] Add Example Story for Detailed Results Component (ampproject#35450)
  🐛 Fix error on bento example (ampproject#35490)
  🐛 amp-story-grid-layer: Fix AMP invalidation error in documentation (ampproject#35503)
  🐛 Fix code formatting (ampproject#35499)
  ✅ buildDom: add tests for amp-fit-text and amp-layout (ampproject#35494)
  ♻️ Remove unused imports (ampproject#35435)
  ✨ amp-connatix-player: iframe domain based on a property (ampproject#35179)
  Updated document with use cases of remote config (ampproject#35496)
  AMP.goBack: update documentation (ampproject#29290)
  🏗 Allow the bundle-size job to run even if the builds were skipped (ampproject#35492)
  build-system: improve terser/esbuild integration (ampproject#35466)
  🧪 [Story performance] Disable animations on first page to 50% (ampproject#35476)
  📖 [Amp story] [Page attachments] Amp.dev Docs for New Page Attachment Features ampproject#34883 (ampproject#35338)
  🚀 [Story interactive] Rewrite Image URL to Cached URL for Image Quizzes and Polls (ampproject#35375)
  ...
@westonruter
Copy link
Member Author

@honeybadgerdontcare Updating to the latest from main fixed the build problem.

@westonruter westonruter merged commit 4c7d5d7 into ampproject:main Aug 3, 2021
@westonruter westonruter deleted the fix/amp-tiktok-validation branch August 3, 2021 22:30
westonruter added a commit to ampproject/amp-wp that referenced this pull request Aug 4, 2021
pierlon pushed a commit to pierlon/amp-wp that referenced this pull request Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants