Skip to content

Conversation

@Niyibitanga
Copy link
Contributor

Update url processing to keep certain parameters

@Niyibitanga Niyibitanga requested a review from Copilot October 31, 2025 18:23
Copy link

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 adds a new keep configuration option to preserve specific URL query parameters from being truncated during URL scrubbing. The feature reorders query strings to move "kept" parameters to the front, ensuring they remain within the maxUrlLength limit when truncation occurs.

Key changes:

  • Added keep parameter to the Config interface alongside existing drop parameter
  • Implemented logic to reorder query parameters, placing kept parameters first
  • Initialized default keep configuration as an empty array

Reviewed Changes

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

File Description
packages/clarity-js/types/core.d.ts Added keep?: string[] to Config interface
packages/clarity-js/src/core/config.ts Initialized default keep configuration as empty array
packages/clarity-js/src/core/scrub.ts Implemented query parameter reordering logic to prioritize kept parameters before truncation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +122 to +124
if (kept.length > 0) {
result = path + "?" + kept.concat(others).join("&");
}
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

[nitpick] The condition if (kept.length > 0) means that if no kept parameters are found, the result remains unchanged even though the keep configuration was specified. This could lead to confusion. Consider removing this check and always reconstructing the query string when keep is configured, or document this behavior explicitly.

Suggested change
if (kept.length > 0) {
result = path + "?" + kept.concat(others).join("&");
}
// Always reconstruct the query string when keep is specified, even if no kept parameters are found
const newQuery = kept.concat(others).join("&");
result = newQuery.length > 0 ? path + "?" + newQuery : path;

Copilot uses AI. Check for mistakes.
@Niyibitanga Niyibitanga requested a review from Copilot October 31, 2025 18:41
@Niyibitanga Niyibitanga marked this pull request as ready for review October 31, 2025 18:41
@Niyibitanga Niyibitanga changed the title Ninosa/url update Update Url Processing Oct 31, 2025
Copy link

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
});
if (kept.length > 0) {
result = path + "?" + kept.concat(others).join("&");
Copy link
Collaborator

Choose a reason for hiding this comment

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

wont this mess up the param following keep?

}

if (truncate) {
result = result.substring(0, maxUrlLength);
Copy link
Member

Choose a reason for hiding this comment

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

Should keep override truncate?

let keep = config.keep;
if (drop && drop.length > 0 && input && input.indexOf("?") > 0) {
let [path, query] = input.split("?");
let swap = Data.Constant.Dropped;
Copy link
Member

Choose a reason for hiding this comment

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

Might be simpler and less code to merge the drop of keep logic into a single process of args.

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.

4 participants