-
Notifications
You must be signed in to change notification settings - Fork 155
Description
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:
- Configure the Scalar path property to a value ending with a trailing slash (e.g.,
/) - Request the documentation page from the controller
- Observe: The generated HTML contains
<script src="//scalar.js"></script>instead of<script src="/scalar.js"></script> - 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
- Run the test suite with
mvn testor your IDE's test runner - Verify that the new test
shouldUseCorrectScalarJsUrlWhenPathIsSetToRootpasses - Verify that all existing tests in
ScalarControllerTeststill pass - Manually test by setting the path configuration to
/and confirming the generated HTML contains the correct script tag with a single slash - 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