Skip to content

🐛 fix: Subdomains offset handling #3495

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 13 commits into from
Jun 5, 2025
Merged

🐛 fix: Subdomains offset handling #3495

merged 13 commits into from
Jun 5, 2025

Conversation

gaby
Copy link
Member

@gaby gaby commented May 31, 2025

Summary

  • handle negative subdomain offsets gracefully
  • handle ports in domains
  • update docs
  • add more test cases

@gaby gaby added the codex label May 31, 2025 — with ChatGPT Connector
Copy link
Contributor

coderabbitai bot commented May 31, 2025

Walkthrough

The logic of the Subdomains method in DefaultCtx was updated to return an empty slice when the offset is negative or exceeds the number of subdomain parts. The method now uses Hostname() to exclude ports before splitting. Tests were expanded to cover various offset values, including zero, negative, and offsets larger than the subdomain count, as well as hosts with ports. Documentation was revised to clarify behavior and provide detailed examples.

Changes

File(s) Change Summary
ctx.go Rewrote Subdomains method to return empty slice for negative or excessive offsets; use Hostname() to exclude ports.
ctx_test.go Refactored Test_Ctx_Subdomains to table-driven tests covering multiple offset scenarios, including edge cases and hosts with ports.
docs/api/ctx.md Updated Subdomains method documentation to clarify offset behavior with detailed table and corrected examples; minor edits to Download method docs.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant DefaultCtx

    Test->>DefaultCtx: Subdomains(offset)
    alt offset < 0 or offset ≥ subdomain count
        DefaultCtx-->>Test: []
    else if offset == 0
        DefaultCtx-->>Test: all subdomain parts
    else
        DefaultCtx-->>Test: subdomain parts excluding last offset labels
    end
Loading

Suggested labels

📒 Documentation

Suggested reviewers

  • ReneWerner87
  • sixcolors
  • efectn

Poem

🐇
When offsets fall below the line,
Empty slices now align.
Ports trimmed off, the dots divide,
Subdomains clear, no place to hide.
Tests hop in with cases bright—
Code refined, all running right! 🥕


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.

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.

@gaby gaby changed the title Fix Subdomains offset handling 🐛 fix: Subdomains offset handling May 31, 2025
@gaby gaby added this to v3 May 31, 2025
@gaby gaby added this to the v3 milestone May 31, 2025
@gaby gaby moved this to In Progress in v3 May 31, 2025
@gaby gaby marked this pull request as ready for review May 31, 2025 16:10
@Copilot Copilot AI review requested due to automatic review settings May 31, 2025 16:10
@gaby gaby requested a review from a team as a code owner May 31, 2025 16:10
@gaby gaby requested review from sixcolors, ReneWerner87 and efectn May 31, 2025 16:10
Copy link
Contributor

@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 fixes subdomain offset handling, ensuring that when an offset exceeds the available subdomains the method returns an empty slice. The changes include updating the test expectations in ctx_test.go and modifying the Subdomains logic in ctx.go to avoid slice bounds errors.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
ctx_test.go Updated tests to reflect the corrected subdomain handling.
ctx.go Modified Subdomains to return an empty slice when the offset makes the slice value non-positive.
Comments suppressed due to low confidence (1)

ctx.go:1760

  • When the host contains only a single segment (e.g. 'localhost'), the current logic does not return an empty slice even though the new behavior expects it. Consider adding a condition (e.g. if len(subdomains) <= 1 { return [] }) before calculating the offset to ensure consistent subdomain handling.
l := len(subdomains) - o

Copy link

codecov bot commented May 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.84%. Comparing base (9409e4f) to head (3081184).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3495      +/-   ##
==========================================
- Coverage   83.87%   83.84%   -0.04%     
==========================================
  Files         120      120              
  Lines       12272    12278       +6     
==========================================
+ Hits        10293    10294       +1     
- Misses       1555     1559       +4     
- Partials      424      425       +1     
Flag Coverage Δ
unittests 83.84% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaby gaby marked this pull request as draft June 1, 2025 04:45
github-actions[bot]

This comment was marked as outdated.

@ReneWerner87
Copy link
Member

@gaby check markdown lint

@gaby gaby marked this pull request as ready for review June 4, 2025 12:01
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: 1

🧹 Nitpick comments (3)
docs/api/ctx.md (3)

1347-1352: Nit: unify “sub-domain” terminology
The term “sub-domain” is hyphenated here, but elsewhere the code and docs use “subdomain” as one word. For consistency and to avoid confusion, consider changing “sub-domain” → “subdomain.”

🧰 Tools
🪛 LanguageTool

[misspelling] ~1347-~1347: This word is normally spelled as one.
Context: ...omains Returns a slice with the host’s sub-domain labels. The dot-separated parts that pr...

(EN_COMPOUNDS_SUB_DOMAIN)


1363-1372: Enhance examples to cover edge cases
Great interactive example. To fully illustrate the updated logic, add:

  • A case for offset > count (e.g., c.Subdomains(10) // [])
  • An example with a port in the host (e.g., Host: "tobi.ferrets.example.com:8080" → c.Subdomains() // ["tobi","ferrets"])
    This will help users understand both the port‐stripping and out‐of‐range behavior.

1600-1602: Nit: clarify default filename handling
It’s worth noting that the default filename= parameter uses the basename of the given path (not the full path). Consider updating to:
“By default, the filename= parameter is set to the file’s basename (e.g., report-12345.pdf), not the full path.”

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d7da88 and 3d1b836.

📒 Files selected for processing (3)
  • ctx.go (1 hunks)
  • ctx_test.go (1 hunks)
  • docs/api/ctx.md (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • ctx.go
  • ctx_test.go
🧰 Additional context used
🪛 LanguageTool
docs/api/ctx.md

[misspelling] ~1347-~1347: This word is normally spelled as one.
Context: ...omains Returns a slice with the host’s sub-domain labels. The dot-separated parts that pr...

(EN_COMPOUNDS_SUB_DOMAIN)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: repeated
  • GitHub Check: Compare

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)
docs/api/ctx.md (1)

1347-1347: Correct compound spelling.

“sub-domain” should be one word: “subdomain”.
Apply:

- Returns a slice with the host’s sub-domain labels.
+ Returns a slice with the host’s subdomain labels.
🧰 Tools
🪛 LanguageTool

[misspelling] ~1347-~1347: This word is normally spelled as one.
Context: ...omains Returns a slice with the host’s sub-domain labels. The dot-separated parts that pr...

(EN_COMPOUNDS_SUB_DOMAIN)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d1b836 and f12a933.

📒 Files selected for processing (1)
  • docs/api/ctx.md (2 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/api/ctx.md

[misspelling] ~1347-~1347: This word is normally spelled as one.
Context: ...omains Returns a slice with the host’s sub-domain labels. The dot-separated parts that pr...

(EN_COMPOUNDS_SUB_DOMAIN)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Compare
  • GitHub Check: repeated
  • GitHub Check: unit (1.24.x, macos-13)
  • GitHub Check: unit (1.24.x, windows-latest)
🔇 Additional comments (3)
docs/api/ctx.md (3)

1349-1354: Description and signature update looks good.

The default offset explanation and the new variadic offset ...int signature correctly reflect the implementation.


1356-1363: Subdomain offset behavior table is comprehensive.

The table now clearly covers omitted (default), valid ranges, boundary and invalid cases.


1370-1373: Examples accurately reflect new behavior.

The sample outputs for default, positive, zero and negative offsets match the implementation.

@ReneWerner87 ReneWerner87 requested a review from sixcolors June 4, 2025 15:02
@ReneWerner87 ReneWerner87 merged commit f9eec85 into main Jun 5, 2025
14 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in v3 Jun 5, 2025
@gaby gaby deleted the codex/2025-05-31 branch June 5, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants