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

fixed: aria-labelledby attribute handling to prevent double double quotes from outputting #1088 #1089

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SteveJonesDev
Copy link

@SteveJonesDev SteveJonesDev commented Jan 16, 2025

Description

This PR ensures proper attribute escaping to maintain security and prevent rendering issues in the DOM.

Since pum_get_popup_title() and pum_get_popup_id() are trusted sources this could have been easily solved by removing the esc_attr, but I opted to leave it for extra security and it may be required to meet WPCS.

Related Issue: #1088 (Add proper escaping to aria-labelledby for popups)

Types of changes

Bug fix.

Screenshots

Screenshot 2025-01-16 at 1 02 31 PM

This has been tested in the following browsers

  • Chrome
  • Firefox
  • Edge
  • Safari

Merge Checklist

  • This PR passes all automated checks (will appear once pull request is submitted)
  • My code has been tested in the latest version of WordPress.
  • My code does not have any warnings from ESLint.
  • My code does not have any warnings from StyleLint.
  • My code does not have any warnings from PHPCS.
  • My code follows the WordPress coding standards.
  • My code follows the accessibility standards.
  • All new functions and classes have code documentation.

Summary by CodeRabbit

  • Accessibility Improvements
    • Enhanced popup dialog accessibility by refining how the aria-labelledby attribute is constructed and rendered.
    • Improved conditional handling of accessibility labels in popup templates.

Copy link

coderabbitai bot commented Jan 16, 2025

Walkthrough

The pull request modifies the templates/popup.php file, specifically focusing on how the aria-labelledby attribute is constructed and rendered in the popup dialog's HTML. The changes improve the attribute's handling by separating the logic for setting the attribute and ensuring it is only added when a non-empty label ID is available.

Changes

File Change Summary
templates/popup.php Refactored aria-labelledby attribute generation to separate ID extraction and conditional rendering

Possibly related issues

  • PopupMaker/Popup-Maker#1088: This PR directly addresses the accessibility issue with the aria-labelledby attribute by modifying how the attribute is constructed and escaped, potentially resolving the broken aria reference caused by double quotes.

Poem

🐰 A Rabbit's Aria of Attributes

With quotes escaped and logic clear,
Our popup's label now rings sincere
No broken refs, no double bind
Accessibility, we've redesigned!
Hop to it, code, with grace so bright 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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

@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: 0

🧹 Nitpick comments (1)
templates/popup.php (1)

12-12: Consider updating aria-modal value for better accessibility.

The aria-modal="false" attribute might be misleading. According to ARIA specifications, if the dialog is intended to be modal, it should be set to "true", and if not modal, the attribute should be omitted entirely rather than set to "false".

-<div id="pum-<?php pum_popup_ID(); ?>" role="dialog" aria-modal="false" 
+<div id="pum-<?php pum_popup_ID(); ?>" role="dialog" <?php echo pum_is_popup_modal() ? 'aria-modal="true"' : ''; ?>

Consider adding a helper function pum_is_popup_modal() to determine if the popup should be modal.

Would you like me to help create the helper function implementation?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7757a54 and 169fbd6.

📒 Files selected for processing (1)
  • templates/popup.php (1 hunks)
🧰 Additional context used
🪛 phpstan (2.0.3)
templates/popup.php

13-13: Function esc_attr not found.
Learn more at https://phpstan.org/user-guide/discovering-symbols

(function.notFound)

🔇 Additional comments (2)
templates/popup.php (2)

9-9: Well-structured initialization of the aria-labelledby value!

Good practices observed:

  • Empty title check prevents unnecessary attribute output
  • Consistent ID format using trusted source functions

12-14: Secure and accessible implementation of aria-labelledby!

The implementation properly escapes attributes and follows accessibility best practices.

🧰 Tools
🪛 phpstan (2.0.3)

13-13: Function esc_attr not found.
Learn more at https://phpstan.org/user-guide/discovering-symbols

(function.notFound)

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.

1 participant