Skip to content

Refine "REDACTED" replacement #13796

@koppor

Description

@koppor

In case of an error, they key is removed from the output.

Example:

  1. Enable Web Fetchers
  2. Select "Springer"
  3. Search for "anything"

You will get

Image

The output looks a bit strange as one would expect that only the key is not shown - and thus, the URL makes the impression of being invalid

Task

  1. Modify the constant to have a regex group for the API key:
    private static final Pattern API_KEY_PATTERN = Pattern.compile("(?i)(api|key|api[-_]?key)=[^&]*");
    . Use a "named group" for readability.
  2. Modify getRedactedUrl (
    return API_KEY_PATTERN.matcher(url).replaceAll(REDACTED_STRING);
    ) to replace only the group of the key - and not all.
  3. Make the method returning String instead of Object.
  4. Make the method package private and add @VisibleForTesting
  5. Add test cases - using @ParameterizedTest and @CsvSource. Hint: Use Ctrl+Shift+T to create a test class.

To increase debugging - the first letter of the API key could still be output - please modify the regex accordingly.

Benefits

Learn how regular expressions work in Java

Metadata

Metadata

Assignees

Labels

component: fetchergood first issueAn issue intended for project-newcomers. Varies in difficulty.📍 AssignedAssigned by assign-issue-action (or manually assigned)

Type

No fields configured for task.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions