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: setAssetToStaticUrl regex matcher #497

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

KristinAoki
Copy link
Member

Description

This PR fixes the error of relative asset urls incorrectly rewriting the conversion to the static url. The regex matcher was catching all relative asset url formats:

  • /assets/courseware/v1/hash/asset-v1:org+num+run+type@asset+block/image.jpeg
  • /asset-v1:org+num+run+type@asset+block@image.jpeg
  • /asset-v1:org+num+run+type@asset+block/image.jpeg

This resulted in the first two version rewriting correctly as /static/image.jpeg and the third rewriting incorrectly as /static/assetblockimage.jpeg.

Testing

  1. Open a raw editor
  2. Add an image with a static link
  3. Save the block
  4. Using browser dev tools, copy the link for the image
  5. Reopen the block
  6. Confirm that the static is unaltered
  7. Paste the previously copied image
  8. Add images using the second and third bullet points' format from above
  9. Save the block
  10. Confirm that the newly added images are visible
  11. Reopen the block
  12. Confirm that all the links appear as static links and their names appear correctly
  13. Save block
  14. Confirm that all images are still visible

Repeat the steps in the text editor and advanced problem editor. Also, test opening and save existing content for regular problem editor.

@KristinAoki KristinAoki requested a review from rayzhou-bit July 31, 2024 15:45
Copy link

codecov bot commented Jul 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.90%. Comparing base (3dfc579) to head (97e0de8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #497   +/-   ##
=======================================
  Coverage   88.90%   88.90%           
=======================================
  Files         248      248           
  Lines        4552     4552           
  Branches      946      942    -4     
=======================================
  Hits         4047     4047           
  Misses        472      472           
  Partials       33       33           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@KristinAoki KristinAoki enabled auto-merge (squash) July 31, 2024 16:54
const assetBlockName = src.substring(0, src.search(/("|")/));
const dividedSrc = assetBlockName.split(/\/assets\/.+\/asset-v1:\S+[+]\S+[@]\S+[+]\S+\//);
const dividedSrc = assetBlockName.split(/\/asset-v1:\S+[+]\S+[@]\S+[+]\S+\//);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this not match the regex above?

Copy link
Member Author

Choose a reason for hiding this comment

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

No because I want to catch all the cases were this appears. If you look at the description for the PR, the first and third bullet show the two ways that asset url can be format. The original regex only caught the first version, not the second and was causing the url tow be incorrectly converted.

@rayzhou-bit rayzhou-bit self-requested a review August 1, 2024 19:55
Copy link
Contributor

@rayzhou-bit rayzhou-bit left a comment

Choose a reason for hiding this comment

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

I wasn't able to get the original issue to reproduce in hosted devstack, but the updated code works fine for me.

@KristinAoki KristinAoki merged commit beb4813 into main Aug 1, 2024
10 checks passed
@KristinAoki KristinAoki deleted the KristinAoki/fix-asset-to-static-parsing branch August 1, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants