Skip to content

Issue #18 - [BUG] Paths ending with a slash break the JavaScript URL #25

@rogelio-cmj

Description

@rogelio-cmj

Motivation

Proper path normalization is essential for robust URL construction and ensures the application works correctly regardless of how users configure their paths.

Current Behavior

The buildJsBundleUrl() method in ScalarController concatenates the base path directly with the JavaScript filename using a forward slash separator. When the base path already ends with a slash, this creates a double slash in the resulting URL.

Reproduction Steps:

  1. Configure the Scalar path property to a value ending with a trailing slash (e.g., /)
  2. Request the documentation page from the controller
  3. Observe: The generated HTML contains <script src="//scalar.js"></script> instead of <script src="/scalar.js"></script>
  4. Expected: The URL should have a single slash, but actual result has a double slash which breaks the script loading

Expected Behavior

The JavaScript bundle URL should always be correctly formatted with single slashes between path segments, regardless of whether the configured base path has a trailing slash or not. The system should normalize paths before concatenation to prevent malformed URLs.

Acceptance Criteria:

  • When the base path is set to /, the JavaScript URL is /scalar.js (not //scalar.js)
  • When the base path has a trailing slash, it is removed before concatenating with the filename
  • The existing functionality for paths without trailing slashes continues to work correctly
  • A test verifies the correct URL generation when the path is set to root with a trailing slash
  • All existing tests continue to pass

Steps To Test

  1. Run the test suite with mvn test or your IDE's test runner
  2. Verify that the new test shouldUseCorrectScalarJsUrlWhenPathIsSetToRoot passes
  3. Verify that all existing tests in ScalarControllerTest still pass
  4. Manually test by setting the path configuration to / and confirming the generated HTML contains the correct script tag with a single slash
  5. Test with other path configurations (with and without trailing slashes) to ensure backward compatibility

Submission

Download https://cap.so/ to record your screen (use Studio mode). Export as an mp4, and drag and drop into an issue comment below.

Guide to submitting pull requests: https://hackmd.io/@timothy1ee/Hky8kV3hlx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions