Skip to content

fix: closing tag regex#7572

Closed
HonLuk wants to merge 2 commits intomakeplane:previewfrom
HonLuk:fix-closeing-tag-regex
Closed

fix: closing tag regex#7572
HonLuk wants to merge 2 commits intomakeplane:previewfrom
HonLuk:fix-closeing-tag-regex

Conversation

@HonLuk
Copy link

@HonLuk HonLuk commented Aug 12, 2025

Description

Fixed an issue with HTML closing tag validation logic. The original regular expressions failed to properly recognize custom component tags (e.g., <image-component></image-component>), causing the system to incorrectly reject saves when documents contained more than 10 images due to perceived HTML structure issues.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

image but match image

Test Scenarios

  1. Test document saving with standard HTML tags (e.g., <div>, <p>)
  2. Test document saving with custom component tags (e.g., <image-component>)
  3. Test document saving with more than 10 images
  4. Test document saving with mixed standard and custom tags

References

Key Changes:

  • Updated regex patterns to properly match custom tags containing hyphens
  • Adjusted tolerance mechanism to prevent false HTML structure validation with custom tags
  • Added support for modern HTML5 self-closing tags

Summary by CodeRabbit

  • Bug Fixes
    • Improved HTML/content validation to correctly recognize closing tags that include hyphens or custom tag names.
    • Reduces false validation errors when submitting or importing rich text/HTML from various editors or component libraries.
    • Enhances compatibility with diverse and modern HTML inputs, leading to fewer rejections and smoother content handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 12, 2025

Walkthrough

Adjusted the HTML closing-tag regex in validate_html_content to accept hyphenated tag names (e.g., x-tag); no other logic or public APIs were changed.

Changes

Cohort / File(s) Summary of Changes
Content Validation Utility
apps/api/plane/utils/content_validator.py
Changed closing-tag regex from r"</(\w+)>" to r"</([\w-]+)>" so closing tags with hyphens are recognized; no further code alterations.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

I twitch my nose at tags that hide,
Now hyphens join the closing side;
A hop, a sniff, the parser's keen,
Finds names with dashes in-between.
Nibble, validate, then rest—good night. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5fa9cf and 67f5006.

📒 Files selected for processing (1)
  • apps/api/plane/utils/content_validator.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/plane/utils/content_validator.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
apps/api/plane/utils/content_validator.py (1)

202-203: Increase HTML tag mismatch tolerance and extend SELF_CLOSING_TAGS

The hard-coded tolerance of 10 unmatched tags combined with a very small set of self-closing tags (img, br, hr, etc.) can easily be exceeded in real-world content (many images, inputs, Meta/Link tags or custom components like <Image />). This will produce false positives on otherwise valid HTML. Please:

• In apps/api/plane/utils/content_validator.py, expand SELF_CLOSING_TAGS to include all HTML5 void elements (area, base, col, embed, input, keygen, link, meta, param, source, track, wbr) and any framework-specific self-closing components you use.
• Replace the magic number 10 with a named constant (e.g. HTML_TAG_TOLERANCE) and choose a higher default (e.g. 20–30), or derive it dynamically based on total tag count.
• Optionally, filter out any tag matched by the self-closing regex /<\w+[^>]*\/>/ so you don’t have to maintain an exhaustive list.

Suggested diff:

--- a/apps/api/plane/utils/content_validator.py
+++ b/apps/api/plane/utils/content_validator.py
@@ -15,6 +15,15 @@
 # HTML self-closing tags that don’t need closing tags
 SELF_CLOSING_TAGS = {
     "img", "br", "hr",
+    # void elements
+    "area", "base", "col", "embed",
+    "input", "keygen", "link", "meta",
+    "param", "source", "track", "wbr",
+    # Add any framework-specific self-closing components here
+}
+
+# Maximum allowed unmatched tags for basic structure validation
+HTML_TAG_TOLERANCE = 20
@@ -200,7 +209,7 @@
         opening_tags_filtered = [
             tag for tag in opening_tags if tag.lower() not in SELF_CLOSING_TAGS
         ]
-        if len(opening_tags_filtered) > len(closing_tags) + 10:
+        if len(opening_tags_filtered) > len(closing_tags) + HTML_TAG_TOLERANCE:
             return False, "HTML content appears to be malformed (unmatched tags)"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d317755 and d5fa9cf.

📒 Files selected for processing (1)
  • apps/api/plane/utils/content_validator.py (1 hunks)

@HonLuk HonLuk closed this Aug 12, 2025
@HonLuk HonLuk reopened this Aug 12, 2025
@NarayanBavisetti
Copy link
Collaborator

Hey @HonLuk, we had already identified this issue and it has been fixed in PR #7608
. Thank you for your contribution. For now, I’ll be closing this PR. If you’re still facing any related issues, please let us know.

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