Skip to content

πŸ› οΈ DX: Support full URLs for users and prevent double-encoding#200

Open
bartholomej wants to merge 1 commit into
masterfrom
dx/support-full-urls-722844711197869297
Open

πŸ› οΈ DX: Support full URLs for users and prevent double-encoding#200
bartholomej wants to merge 1 commit into
masterfrom
dx/support-full-urls-722844711197869297

Conversation

@bartholomej

@bartholomej bartholomej commented Jun 4, 2026

Copy link
Copy Markdown
Owner

πŸ’‘ What: Added full URL parsing support across all primary CSFD scrapers and URL builders (userRatings, userReviews, vars.ts).

🎯 Why: Developers often copy-paste full HTTP URLs from their browsers directly into the API (e.g. csfd.userRatings('https://www.csfd.cz/uzivatel/912-bart/hodnoceni/')). Previously, passing a full URL to User APIs triggered a 404 error because the URL builders blindly encoded the entire string. By systematically passing inputs through the extractId helper, the library now safely ignores trailing paths and returns canonical endpoints.

πŸš€ Examples:

// Before: Throws 404 (encodes full url)
await csfd.userRatings('https://www.csfd.cz/uzivatel/912-bart/hodnoceni/');

// After: Works perfectly, seamlessly extracts ID "912"
await csfd.userRatings('https://www.csfd.cz/uzivatel/912-bart/hodnoceni/');

PR created automatically by Jules for task 722844711197869297 started by @bartholomej

Summary by CodeRabbit

New Features

  • User, movie, and creator lookup functions now accept flexible input formatsβ€”both full URLs and direct IDs. The library automatically extracts and normalizes the canonical ID for consistent processing.

Tests

  • Expanded test coverage for URL input normalization across library helpers, ensuring reliable behavior with multiple input formats.

…ble-encoding

- Enhance UserRatingsScraper and UserReviewsScraper to correctly extract numeric IDs from full CSFD URLs instead of breaking on double-encoding.
- Update global `userUrl`, `movieUrl`, and `creatorUrl` builders in `vars.ts` to smartly ignore trailing paths and automatically extract the ID using `extractId`.
- Adds tests in `tests/vars.test.ts` to assert that full URLs correctly return canonical endpoint URLs.

Co-authored-by: bartholomej <5861310+bartholomej@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

πŸ“ Walkthrough

Walkthrough

This PR enhances ID handling across URL construction by extracting numeric IDs from various URL formats. The parser recognizes numeric-only path segments, core URL builders normalize user/movie/creator inputs via extractId before encoding, and user-ratings and user-reviews services leverage this normalization for consistent pagination URL construction. Tests validate the normalization behavior.

Changes

URL ID Normalization Enhancement

Layer / File(s) Summary
URL ID parsing enhancement
src/helpers/global.helper.ts
parseIdFromUrl adds recognition of numeric-only URL path segments to extract IDs in addition to the existing dash-prefixed slug pattern.
URL builder normalization
src/vars.ts
userUrl, movieUrl, and creatorUrl now normalize inputs via extractId (with fallback to original value) before encoding. The movieUrl signature is widened to accept number | string.
User ratings service integration
src/services/user-ratings.service.ts
UserRatingsScraper.userRatings uses extractId to canonicalize the user argument for both initial and paginated URL construction.
User reviews service integration
src/services/user-reviews.service.ts
UserReviewsScraper.userReviews uses extractId to canonicalize the user argument for base and paginated URL construction.
URL normalization test coverage
tests/vars.test.ts
Tests verify that userRatingsUrl, movieUrl, and creatorUrl correctly normalize full URLs and paths to canonical endpoint formats.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • bartholomej/node-csfd-api#66: Overlaps with user-ratings service pagination refactor; both modify URL and request flow for paginated user ratings.
  • bartholomej/node-csfd-api#67: Related user-reviews service changes; both enhance user-review URL construction and pagination with extractId-based normalization.

Suggested labels

enhancement

Poem

🐰 A rabbit hops through twisted URLs with glee,
Extracting IDs from paths, both slug and number free!
Now ratings, reviews, and builders all align,
Each canonical form shines, crystal and fine.
The pagination flows smooth as carrots combineβ€”
URL chaos resolved, by extractId's design! πŸ₯•

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description explains what changed (full URL parsing), why it matters (404 errors on copy-paste URLs), and provides practical examples, but lacks the structured template sections (Type of change, Related Issues, Checklist). Add the structured template sections: mark the Type of change (appears to be Refactoring/Bug fix), add Related Issues, and complete the Checklist to ensure consistency with repository standards.
βœ… Passed checks (4 passed)
Check name Status Explanation
Title check βœ… Passed The title clearly and concisely describes the main functional changes: adding full URL support and preventing double-encoding issues across the codebase.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dx/support-full-urls-722844711197869297

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

πŸ”§ ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 98.72%. Comparing base (b0930c2) to head (c53f81e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #200   +/-   ##
=======================================
  Coverage   98.71%   98.72%           
=======================================
  Files          34       34           
  Lines         781      785    +4     
  Branches      202      206    +4     
=======================================
+ Hits          771      775    +4     
  Misses         10       10           

β˜” View full report in Codecov by Harness.
πŸ“’ 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.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/vars.test.ts (1)

13-16: ⚑ Quick win

Add explicit path-only normalization test cases.

Coverage is strong for full URLs, but adding /uzivatel/..., /film/..., and /tvurce/... path-only inputs here would better lock the normalization contract and prevent regressions.

Suggested test additions
 describe('Vars User Ratings', () => {
+  test('Assemble User rating with full path', () => {
+    const url = userRatingsUrl('/uzivatel/912-bart/hodnoceni/');
+    expect(url).toBe('https://www.csfd.cz/uzivatel/912/hodnoceni/');
+  });
 });
 
 describe('Vars Movies', () => {
+  test('Assemble movieUrl with full path', () => {
+    const url = movieUrl('/film/535121-zlatokopky/', {});
+    expect(url).toBe('https://www.csfd.cz/film/535121/prehled/');
+  });
 });
 
 describe('Vars Creator', () => {
+  test('Assemble creatorUrl with full path', () => {
+    const url = creatorUrl('/tvurce/1-mel-gibson/', {});
+    expect(url).toBe('https://www.csfd.cz/tvurce/1');
+  });
 });
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/vars.test.ts` around lines 13 - 16, Add explicit unit tests that pass
path-only strings (e.g. '/uzivatel/912-bart', '/film/123-nazev',
'/tvurce/45-jmeno') to the normalization functions to ensure they produce full
normalized URLs; specifically add cases alongside the existing userRatingsUrl
test that call userRatingsUrl with '/uzivatel/912-bart' and assert
'https://www.csfd.cz/uzivatel/912/hodnoceni/', and add equivalent path-only
tests for the corresponding film and creator normalization functions (e.g.
filmRatingsUrl and tvurce/creatorRatingsUrl) to assert their expected normalized
outputs.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/vars.test.ts`:
- Around line 13-16: Add explicit unit tests that pass path-only strings (e.g.
'/uzivatel/912-bart', '/film/123-nazev', '/tvurce/45-jmeno') to the
normalization functions to ensure they produce full normalized URLs;
specifically add cases alongside the existing userRatingsUrl test that call
userRatingsUrl with '/uzivatel/912-bart' and assert
'https://www.csfd.cz/uzivatel/912/hodnoceni/', and add equivalent path-only
tests for the corresponding film and creator normalization functions (e.g.
filmRatingsUrl and tvurce/creatorRatingsUrl) to assert their expected normalized
outputs.

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 594b1c11-dd20-4f64-bc45-05598804638e

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between b0930c2 and c53f81e.

πŸ“’ Files selected for processing (6)
  • demo.ts
  • src/helpers/global.helper.ts
  • src/services/user-ratings.service.ts
  • src/services/user-reviews.service.ts
  • src/vars.ts
  • tests/vars.test.ts
πŸ’€ Files with no reviewable changes (1)
  • demo.ts

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