Skip to content

Improving url validation regex#1799

Merged
thesocialdev merged 5 commits intostagefrom
Improving-url-validation-regex
Feb 8, 2025
Merged

Improving url validation regex#1799
thesocialdev merged 5 commits intostagefrom
Improving-url-validation-regex

Conversation

@LuizFNJ
Copy link
Collaborator

@LuizFNJ LuizFNJ commented Jan 25, 2025

Description

I limited the TLD to two characters from 'a' to 'z', so it accepts more options without restricting it to a set of TLDs. Additionally, I created a unit test to test some various URLs. The test uses a forEach on an array of predefined links, applying the URL pattern.

In conversation with @caneppelevitor, he conducted an in-depth investigation, and it was agreed that a change is needed in how we run Jest tests on the platform, as well as the possibility of separating the tests. Since this change may require a greater effort, it might make more sense to implement it in another PR.

In this PR, I kept the improvement of the pattern and encapsulated it in another component so that we can test only the URL validation functionality. I placed the test file in the appropriate location, alongside the component that contains this functionality, as it is independent and should not undergo changes after we fix and separate the unit tests on the platform.

Fixes #1791

Type of change

  • Existing feature enhancement (non-breaking change which modifies existing functionality)

Testing

Create a font in the report and test with various types of TLDs.

Developer Checklist

General

  • Code is appropriately commented, particularly in hard-to-understand areas
  • Repository documentation has been updated (Readme.md) with additional steps required for a local environment setup.
  • No console.log or related logging is added.
  • No code is repeated/duplicated in violation of DRY. The exception to this is for new (MVP/Prototype) functionality where the abstraction layer may not be clear (comments should be added to explain the violation of DRY in these scenarios).
  • Documented with TSDoc all library and controller new functions

Tests

  • All existing unit and end to end tests pass across all services
  • Unit and end to end tests have been added to ensure backend APIs behave as expected

Merge Request Review Checklist

  • An issue is linked to this PR and these changes meet the requirements outlined in the linked issue(s)
  • High risk and core workflows have been tested and verified in a local environment.
  • Enhancements or opportunities to improve performance, stability, security or code readability have been noted and documented in JIRA issues if not being addressed.
  • Any dependent changes have been merged and published in downstream modules
  • Changes to multiple services can be deployed in parallel and independently. If not, changes should be broken out into separate merge requests and deployed in order.

@LuizFNJ LuizFNJ requested a review from thesocialdev as a code owner January 25, 2025 23:15
@LuizFNJ LuizFNJ force-pushed the Improving-url-validation-regex branch from ba6389e to 5a06010 Compare January 27, 2025 21:12
@LuizFNJ LuizFNJ force-pushed the Improving-url-validation-regex branch from 5a06010 to f85f330 Compare February 3, 2025 20:22
@caneppelevitor
Copy link
Collaborator

The issue on test-lint occurs because of the way Jest resolves modules when rootDir is changed in the Jest config.

When using:

import * as mongoose from "mongoose";

Jest treats mongoose as an ES module, which can cause mongoose.Types to become undefined in certain configurations.

The correct approach is to use:

import mongoose from "mongoose";

This ensures that the CommonJS default export is correctly resolved, avoiding issues when Jest's rootDir is modified.

Fix: Replace all instances of import * as mongoose from "mongoose"; with import mongoose from "mongoose"; throughout the project to ensure proper module resolution

@LuizFNJ LuizFNJ force-pushed the Improving-url-validation-regex branch 2 times, most recently from 59c52fe to cbf7f6a Compare February 3, 2025 20:50
@LuizFNJ LuizFNJ force-pushed the Improving-url-validation-regex branch from d80fa3d to 89875ea Compare February 4, 2025 20:27
@LuizFNJ LuizFNJ force-pushed the Improving-url-validation-regex branch from 89875ea to 6e781c8 Compare February 4, 2025 20:50
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2025

@thesocialdev thesocialdev merged commit 5f26943 into stage Feb 8, 2025
6 of 7 checks passed
@thesocialdev thesocialdev deleted the Improving-url-validation-regex branch February 8, 2025 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: QA

Development

Successfully merging this pull request may close these issues.

Enhance URL validation regex to support additional TLDs

3 participants