Skip to content

Fix parsing of srcset with whitespaces #458

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

Merged
merged 1 commit into from
Mar 30, 2025

Conversation

snshn
Copy link
Member

@snshn snshn commented Mar 30, 2025

No description provided.

@snshn snshn requested a review from Copilot March 30, 2025 00:27
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR aims to fix the parsing of srcset attributes containing whitespaces by refining the parsing logic. It introduces a new test module with various srcset examples, exposes the SrcSetItem struct for broader use, and updates the srcset parsing function to correctly handle empty string cases.

  • Added tests to validate the parsing of srcset strings with different whitespace characters.
  • Made the SrcSetItem struct public to allow external access.
  • Adjusted the loop logic in parse_srcset to increment the index when encountering empty tokens.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/html/parse_srcset.rs New test suite for verifying srcset parsing behavior with whitespace handling.
tests/html/mod.rs Registered the new parse_srcset test module.
src/html.rs Made SrcSetItem public, added constants for whitespace characters, and updated loop logic in parse_srcset.

src/html.rs Outdated
@@ -396,6 +396,7 @@ pub fn parse_srcset(srcset: &str) -> Vec<SrcSetItem> {

// Skip empty strings
if partial.is_empty() {
i += 1;
Copy link
Preview

Copilot AI Mar 30, 2025

Choose a reason for hiding this comment

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

Manually incrementing the loop counter within the empty-string handling block may introduce off-by-one errors. Please review the loop structure to ensure that the counter is incremented consistently, avoiding unintended skips of valid tokens.

Copilot uses AI. Check for mistakes.

@snshn snshn force-pushed the srcset-white-space-fix branch from db8972d to fa4e766 Compare March 30, 2025 00:33
@snshn snshn requested a review from Copilot March 30, 2025 00:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses the issue with parsing srcset attributes that contain whitespaces by improving the parsing logic and adding a dedicated test.

  • Added tests in tests/html/parse_srcset.rs to verify correct handling of srcset strings with multiple items and varied whitespace.
  • Made the SrcSetItem struct public and introduced constants for ASCII whitespaces to support the improved parser logic.
  • Adjusted the loop counter logic in parse_srcset to ensure proper iteration over srcset parts.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/html/parse_srcset.rs Added tests for multiple srcset items with whitespaces.
tests/html/mod.rs Included the new parse_srcset module in the test module.
src/html.rs Made SrcSetItem public, added whitespace constant, and refactored loop increment in parse_srcset.

@@ -394,6 +394,8 @@ pub fn parse_srcset(srcset: &str) -> Vec<SrcSetItem> {
while i < partials.len() {
let partial = partials[i];

Copy link
Preview

Copilot AI Mar 30, 2025

Choose a reason for hiding this comment

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

[nitpick] The repositioning of the loop counter increment may be unclear to readers; consider adding a comment explaining why the increment is done before processing the current partial to aid future maintainers.

Suggested change
// Increment the loop counter before processing the current partial
// to handle cases where the partial is split and reinserted into the list.

Copilot uses AI. Check for mistakes.

@snshn snshn merged commit 03ad5e8 into Y2Z:master Mar 30, 2025
4 checks passed
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