Skip to content

HttpRequestPatternFix#12

Merged
hawkeyexl merged 3 commits intomainfrom
httpRequestPatternFix
Jun 3, 2025
Merged

HttpRequestPatternFix#12
hawkeyexl merged 3 commits intomainfrom
httpRequestPatternFix

Conversation

@hawkeyexl
Copy link
Contributor

@hawkeyexl hawkeyexl commented Jun 3, 2025

  • Check for existence of all $n variables before substitution
  • Return null if any variable is missing
  • Delete keys from stringOrObject if their corresponding $n variables are missing
  • Clean up formatting for better readability

Summary by CodeRabbit

  • Bug Fixes

    • Improved parsing of HTTP request blocks in markdown to support both Unix and Windows line endings.
    • Enhanced variable substitution logic to prevent incomplete replacements when required values are missing.
  • Refactor

    • Reformatted test filtering logic for improved readability.

hawkeyexl added 2 commits June 3, 2025 11:04
- Check for existence of all $n variables before substitution
- Return null if any variable is missing
- Delete keys from stringOrObject if their corresponding $n variables are missing
- Clean up formatting for better readability
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

This update refines the regex pattern for parsing HTTP request blocks in markdown to support both Unix and Windows line endings and improves header/body extraction. Additionally, it enhances variable substitution logic in the parsing utility to prevent incomplete replacements by ensuring all referenced variables are defined before substitution.

Changes

File(s) Summary
src/config.js Updated the regex pattern for "httpRequestFormat" to handle both \n and \r\n line endings, and improved header/body capture logic.
src/utils.js Enhanced replaceNumericVariables to check for all referenced variables before substitution; improved test filtering readability.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MarkdownParser
    participant VariableSubstitutor

    User->>MarkdownParser: Provide markdown with HTTP request block
    MarkdownParser->>MarkdownParser: Apply refined regex (handles \n/\r\n, headers, body)
    MarkdownParser->>VariableSubstitutor: Detect variables ($n) in content
    VariableSubstitutor->>VariableSubstitutor: Check all variables are defined
    alt All variables defined
        VariableSubstitutor->>MarkdownParser: Substitute variables
    else Some variables missing
        VariableSubstitutor->>MarkdownParser: Return null or remove key
    end
    MarkdownParser->>User: Return parsed and substituted content
Loading

Possibly related PRs

Poem

In the land of code, where patterns roam free,
Regexes now handle both \n and \r\n with glee.
Variables checked, no more partial swap—
Only complete replacements, never a flop!
With headers and bodies parsed just right,
This bunny hops off, code shining bright.
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05b6f7a and 95e867a.

📒 Files selected for processing (1)
  • src/utils.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/utils.js
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

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

🧹 Nitpick comments (1)
src/utils.js (1)

305-305: Use modern Object.hasOwn() instead of deprecated hasOwnProperty.

The static analysis correctly identifies that direct usage of hasOwnProperty should be replaced with the modern Object.hasOwn() method for better security and consistency.

Apply this diff to modernize the property checks:

-            return (
-              values.hasOwnProperty(index) && typeof values[index] !== "undefined"
-            );
+            return (
+              Object.hasOwn(values, index) && typeof values[index] !== "undefined"
+            );

And:

-            return (
-              values.hasOwnProperty(index) &&
-              typeof values[index] !== "undefined"
-            );
+            return (
+              Object.hasOwn(values, index) &&
+              typeof values[index] !== "undefined"
+            );

Also applies to: 335-335

🧰 Tools
🪛 Biome (1.9.4)

[error] 305-305: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa41dcd and 05b6f7a.

📒 Files selected for processing (2)
  • src/config.js (1 hunks)
  • src/utils.js (3 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/utils.js

[error] 305-305: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


[error] 335-335: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test (windows-latest, 24)
🔇 Additional comments (4)
src/config.js (1)

113-113: Excellent cross-platform compatibility improvement!

The regex pattern now correctly handles both Unix (\n) and Windows (\r\n) line endings by adding optional carriage returns (\r?) before newlines. This ensures HTTP request blocks in markdown are parsed consistently across different operating systems.

src/utils.js (3)

298-317: Robust variable validation prevents incomplete substitutions.

The enhanced logic correctly checks for the existence of all $n variables before performing substitution. Returning null when variables are missing prevents partial or invalid replacements, which aligns well with the PR objectives.

🧰 Tools
🪛 Biome (1.9.4)

[error] 305-305: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


329-351: Consistent handling for object properties with missing variables.

The logic appropriately removes object keys when their corresponding $n variables are undefined, maintaining consistency with the string handling approach. This prevents objects from containing partially resolved content.

🧰 Tools
🪛 Biome (1.9.4)

[error] 335-335: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


695-697: Improved code readability with multi-line formatting.

The reformatting from single-line to multi-line arrow function enhances readability while maintaining the same functionality.

@hawkeyexl hawkeyexl merged commit d757d7f into main Jun 3, 2025
15 checks passed
@hawkeyexl hawkeyexl deleted the httpRequestPatternFix branch June 3, 2025 18:12
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