Skip to content

refactor(urltools): UrlTools is now a namespace#13258

Open
aollier wants to merge 6 commits intokeepassxreboot:developfrom
aollier:refactor/UrlTools
Open

refactor(urltools): UrlTools is now a namespace#13258
aollier wants to merge 6 commits intokeepassxreboot:developfrom
aollier:refactor/UrlTools

Conversation

@aollier
Copy link
Copy Markdown
Contributor

@aollier aollier commented Apr 20, 2026

UrlTools does not need to inherit from QObject or even be a class. It is a collection of regular functions.

Type of change

  • ✅ Refactor (significant modification to existing code)

@aollier aollier force-pushed the refactor/UrlTools branch 2 times, most recently from 4c5f8e9 to 682d6f1 Compare April 20, 2026 14:25
@droidmonkey droidmonkey added this to the v2.8.0 milestone Apr 20, 2026
Copy link
Copy Markdown
Contributor

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

Refactors UrlTools from a QObject-based singleton to a pure function collection under the UrlTools namespace, updating callers and tests accordingly.

Changes:

  • Replace UrlTools class/singleton (urlTools()) usage with UrlTools::... namespace function calls.
  • Remove singleton/test fixture setup that is no longer needed.
  • Adjust UrlTools implementation to use internal free helpers instead of private member methods.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/TestUrlTools.h Removes unused test lifecycle hooks and singleton member usage.
tests/TestUrlTools.cpp Updates tests to call UrlTools::... namespace functions directly.
src/gui/entry/EntryURLModel.cpp Switches URL validation/dup-check logic to UrlTools::... calls.
src/gui/UrlTools.h Converts the public API from a class to a UrlTools namespace of functions/constants.
src/gui/UrlTools.cpp Removes singleton implementation; introduces internal helpers; adapts functions to namespace form.
src/gui/URLEdit.cpp Updates URL validation call to UrlTools::isUrlValid.
src/gui/IconDownloader.cpp Updates domain and redirect handling calls to UrlTools::....
src/browser/PasskeyUtils.cpp Updates public-suffix/domain validation helpers to use UrlTools::....
src/browser/BrowserService.cpp Updates base-domain comparison to use UrlTools::getBaseDomainFromUrl.

Comment thread src/gui/UrlTools.cpp Outdated
@aollier aollier force-pushed the refactor/UrlTools branch from e3b9704 to 2832f90 Compare April 21, 2026 07:57
Comment thread src/gui/UrlTools.cpp Outdated
Comment thread src/gui/UrlTools.cpp Outdated
Copy link
Copy Markdown
Member

@varjolintu varjolintu left a comment

Choose a reason for hiding this comment

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

Fix the suggestions + code format in UrlTools.h. Let's see if any build errors appear.

@aollier
Copy link
Copy Markdown
Contributor Author

aollier commented Apr 25, 2026

I think #13275 should be merged first because it can cause build failure (#13274).

aollier added 6 commits April 25, 2026 15:44
UrlTools does not need to inherit from QObject or even be a class.
It is a collection of regular functions.
domainHasIllegalCharacters() constructs a QRegularExpression on every call.
Since the pattern is constant, make it static const QRegularExpression
  to avoid repeated regex compilation in hot paths
  (e.g., domain validation during browsing/passkey operations).
- code format
- use pure Qt functions for the string handling
- use chop to remove the last character of a QString
- make another QRegularExpression static const
@aollier aollier force-pushed the refactor/UrlTools branch from 340c234 to b089b54 Compare April 25, 2026 13:45
Comment thread src/gui/UrlTools.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants