Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and pull back single app functionality #290

Merged

Conversation

atc0005
Copy link
Owner

@atc0005 atc0005 commented Apr 7, 2024

Overview

There are a lot of refactoring changes applied to better support sharing of common logic, clarify intent and in general cleanup the code. Admittedly this would have been better managed by separate smaller PRs but I was "on a roll" and didn't find a good stopping place until I was finished drafting test cases (separate PR).

New functionality has been added to the cmd/eslg app to assist with testdata generation.

Further refactoring is needed once I've had enough time to distance myself from recent changes and can look at the code with fresh eyes.

Added

  • add Encode Randomly button to cmd/eslg app
  • add QueryEscape button to cmd/eslg app
  • add QueryEscape Randomly button to cmd/eslg app

Changed

  • pull back functionality
    • cmd/usl/output
    • pull back ReadURLsFromInput
    • pull back ProcessInputURLs
    • pull back helper functions
  • push down functionality
    • encoding support used by cmd/eslg
    • move private encodeInput func to internal/safelinks/EncodeInput
    • decoding support used by cmd/dslg
    • move private decodeInput func to internal/safelinks/DecodeInput
  • rename Encode button to Encode All in cmd/eslg app
  • cmd/eslg app no longer explicitly sets light theme
    • this causes the app to auto-detect dark/light theming like the cmd/dslg currently does
  • require expected safelinks domain
    • require that the SafeLinksBaseDomain is present in url.URL values considered valid Safe Links URLs
  • require host and scheme values for url.URL values considered valid URLs
  • CleanURL now removes leading/trailing periods
    • the new trimEnclosingURLCharacters func handles this task and the existing angle brackets removal task
  • update GetURL* funcs (and callers) to optionally match non-HTTPS prefixed URLs. This is primarily done to support generating (encoding) testdata files.
  • refactor common behavior from newQueryEscapeButton and
    newEncodeButton funcs to separate newProcessInputButton helper func

Fixed

  • clarify meaning of ErrNoURLsFound error
  • debug logging tweaks and fixes (more needed)
  • use ParsedURL values to package the original URL match pattern, and a parsed version in place of url.URL values
    • provide Trimmed method to return a "clean" version of the original URL pattern
  • clean URLs before performing search/replace operations
  • handle scenario where output == input (failed encoding or query escaping), ensure that empty input error has a trailing newline so that appended errors are displayed properly
  • fix hasAcceptableURLPrefix helper func logic
  • update URLs func to require basic validation steps to pass before considering url.Parse results a valid URL

@atc0005 atc0005 added enhancement New feature or request refactor labels Apr 7, 2024
@atc0005 atc0005 added this to the v0.5.0-alpha.14 milestone Apr 7, 2024
@atc0005 atc0005 self-assigned this Apr 7, 2024
OVERVIEW

There are a *lot* of refactoring changes applied to better support
sharing of common logic, clarify intent and in general cleanup the
code. Admittedly this would have been better managed by separate
smaller PRs but I was "on a roll" and didn't find a good stopping
place until I was finished drafting test cases (separate PR).

New functionality has been added to the `cmd/eslg` app to assist with
testdata generation.

Further refactoring is needed once I've had enough time to distance
myself from recent changes and can look at the code with fresh eyes.

ADDED

- add `Encode Randomly` button to `cmd/eslg` app
- add `QueryEscape` button to `cmd/eslg` app
- add `QueryEscape Randomly` button to `cmd/eslg` app

CHANGED

- pull back functionality
  - `cmd/usl/output`
  - pull back `ReadURLsFromInput`
  - pull back `ProcessInputURLs`
  - pull back helper functions
- push down functionality
  - encoding support used by `cmd/eslg`
  - move private `encodeInput` func to
    `internal/safelinks/EncodeInput`
  - decoding support used by `cmd/dslg`
  - move private `decodeInput` func to
    `internal/safelinks/DecodeInput`
- rename `Encode` button to `Encode All` in `cmd/eslg` app
- `cmd/eslg` app no longer explicitly sets `light` theme
  - this causes the app to auto-detect dark/light theming like the
    `cmd/dslg` currently does
- require expected safelinks domain
  - require that the SafeLinksBaseDomain is present in url.URL values
    considered valid Safe Links URLs
- require host and scheme values for url.URL values considered valid
  URLs
- `CleanURL` now removes leading/trailing periods
  - the new `trimEnclosingURLCharacters` func handles this task and
    the existing angle brackets removal task
- update `GetURL*` funcs (and callers) to optionally match non-HTTPS
  prefixed URLs. This is primarily done to support generating
  (encoding) testdata files.
- refactor common behavior from `newQueryEscapeButton` and
  `newEncodeButton` funcs to separate `newProcessInputButton` helper
  func

FIXES

- clarify meaning of `ErrNoURLsFound` error
- debug logging tweaks and fixes (more needed)
- use ParsedURL values to package the original URL match pattern, and
  a parsed version in place of url.URL values
  - provide `Trimmed` method to return a "clean" version of the
    original URL pattern
- clean URLs before performing search/replace operations
- handle scenario where output == input (failed encoding or query
  escaping), ensure that empty input error has a trailing newline so
  that appended errors are displayed properly
- fix hasAcceptableURLPrefix helper func logic
- update URLs func to require basic validation steps to pass before
  considering url.Parse results a valid URL
@atc0005 atc0005 force-pushed the refactor-and-pull-back-single-app-functionality branch from 1b19666 to d651fd3 Compare April 7, 2024 14:19
@atc0005 atc0005 merged commit 2767ae5 into development Apr 7, 2024
29 checks passed
@atc0005 atc0005 deleted the refactor-and-pull-back-single-app-functionality branch April 7, 2024 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant