-
Notifications
You must be signed in to change notification settings - Fork 53k
fix(gateway): allow [[as_document]] glued directly to MEDIA path #63644
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """Tests for MEDIA_TAG_CLEANUP_RE regex matching behavior (#63632).""" | ||
|
|
||
|
|
||
| class TestMediaTagCleanup: | ||
| """Tests for MEDIA_TAG_CLEANUP_RE regex matching behavior.""" | ||
|
|
||
| def test_media_tag_with_directive_glued_to_extension(self): | ||
| """Regression: MEDIA:<path>[[as_document]] must match when directive is glued | ||
| directly to the extension without whitespace (#63632). | ||
|
|
||
| The fix adds `\\[` to the lookahead character class in MEDIA_TAG_CLEANUP_RE. | ||
| """ | ||
| from gateway.platforms.base import MEDIA_TAG_CLEANUP_RE | ||
|
|
||
| # Issue case: [[as_document]] glued directly to .xlsx | ||
| text = "Готово. MEDIA:/home/hermes/report.xlsx[[as_document]]" | ||
| assert MEDIA_TAG_CLEANUP_RE.search(text) is not None | ||
| stripped = MEDIA_TAG_CLEANUP_RE.sub("", text) | ||
| assert "MEDIA:" not in stripped | ||
| assert "/home/hermes/report.xlsx" not in stripped | ||
|
|
||
| # Same with whitespace (should still work) | ||
| text_with_space = "Готово. MEDIA:/home/hermes/report.xlsx [[as_document]]" | ||
| assert MEDIA_TAG_CLEANUP_RE.search(text_with_space) is not None | ||
| stripped = MEDIA_TAG_CLEANUP_RE.sub("", text_with_space) | ||
| assert "MEDIA:" not in stripped | ||
| assert "/home/hermes/report.xlsx" not in stripped | ||
|
|
||
| # Other directives ([[as_image]]) should also work | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| text_image = "Done. MEDIA:/tmp/chart.png[[as_image]]" | ||
| assert MEDIA_TAG_CLEANUP_RE.search(text_image) is not None | ||
| stripped = MEDIA_TAG_CLEANUP_RE.sub("", text_image) | ||
| assert "MEDIA:" not in stripped | ||
| assert "/tmp/chart.png" not in stripped | ||
|
|
||
| def test_media_tag_with_whitespace_still_works(self): | ||
| """Baseline: MEDIA tags with whitespace before/after still match.""" | ||
| from gateway.platforms.base import MEDIA_TAG_CLEANUP_RE | ||
|
|
||
| # Space before closing quote | ||
| text = "Here is your report: MEDIA:/tmp/report.md " | ||
| stripped = MEDIA_TAG_CLEANUP_RE.sub("", text).strip() | ||
| assert "MEDIA:" not in stripped | ||
| assert "/tmp/report.md" not in stripped | ||
|
|
||
| # Multiple spaces (regex removes tag but preserves surrounding whitespace) | ||
| text = "Report at MEDIA:/tmp/data.pdf done" | ||
| stripped = MEDIA_TAG_CLEANUP_RE.sub("", text) | ||
| assert "MEDIA:" not in stripped | ||
| assert "/tmp/data.pdf" not in stripped | ||
| assert "Report at" in stripped and "done" in stripped | ||
|
|
||
| def test_media_tag_at_end_of_string(self): | ||
| """MEDIA tags at the end of a string should match ($ anchor).""" | ||
| from gateway.platforms.base import MEDIA_TAG_CLEANUP_RE | ||
|
|
||
| text = "Here is the file: MEDIA:/tmp/file.docx" | ||
| stripped = MEDIA_TAG_CLEANUP_RE.sub("", text).strip() | ||
| assert "MEDIA:" not in stripped | ||
| assert "/tmp/file.docx" not in stripped | ||
| assert "Here is the file:" in stripped | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please restrict this new boundary to the literal supported
[[as_document]]directive rather than any[. A generic bracket boundary can makeMEDIA:/safe/report.xlsx[revision]match and deliver the.xlsxprefix, whereas the current anchored parser leaves that unrecognized path intact.