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

[CP STAGING] fix: Bank account - Website in upper-case letters is accepted despite validation error. #52155

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ const translations = {
noBankAccountAvailable: "Sorry, there's no bank account available.",
noBankAccountSelected: 'Please choose an account.',
taxID: 'Please enter a valid tax ID number.',
website: 'Please enter a valid website using lower-case letters.',
website: 'Please enter a valid website.',
zipCode: `Please enter a valid ZIP code using the format: ${CONST.COUNTRY_ZIP_REGEX_DATA.US.samples}.`,
phoneNumber: 'Please enter a valid phone number.',
companyName: 'Please enter a valid business name.',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ const translations = {
noBankAccountAvailable: 'Lo sentimos, no hay ninguna cuenta bancaria disponible.',
noBankAccountSelected: 'Por favor, elige una cuenta bancaria.',
taxID: 'Por favor, introduce un número de identificación fiscal válido.',
website: 'Por favor, introduce un sitio web válido. El sitio web debe estar en minúsculas.',
website: 'Por favor, introduce un sitio web válido.',
zipCode: `Formato de código postal incorrecto. Formato aceptable: ${CONST.COUNTRY_ZIP_REGEX_DATA.US.samples}.`,
phoneNumber: 'Por favor, introduce un teléfono válido.',
companyName: 'Por favor, introduce un nombre comercial legal válido.',
Expand Down
3 changes: 1 addition & 2 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ function getDatePassedError(inputDate: string): string {
* http/https/ftp URL scheme required.
*/
function isValidWebsite(url: string): boolean {
const isLowerCase = url === url.toLowerCase();
return new RegExp(`^${Url.URL_REGEX_WITH_REQUIRED_PROTOCOL}$`, 'i').test(url) && isLowerCase;
return new RegExp(`^${Url.URL_REGEX_WITH_REQUIRED_PROTOCOL}$`, 'i').test(url);
}

/** Checks if the domain is public */
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepCompanyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function IOURequestStepCompanyInfo({route, report, transaction}: IOURequestStepC
if (!ValidationUtils.isValidWebsite(companyWebsite)) {
errors.companyWebsite = translate('bankAccount.error.website');
} else {
const domain = Url.extractUrlDomain(values.companyWebsite);
const domain = Url.extractUrlDomain(companyWebsite);

if (!domain || !Str.isValidDomainName(domain)) {
errors.companyWebsite = translate('iou.invalidDomainError');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import {Str} from 'expensify-common';
import React, {useMemo} from 'react';
import React from 'react';
import {useOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
Expand All @@ -11,7 +11,6 @@ import TextInput from '@components/TextInput';
import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {getDefaultCompanyWebsite} from '@libs/BankAccountUtils';
import * as Url from '@libs/Url';
import * as ValidationUtils from '@libs/ValidationUtils';
import Navigation from '@navigation/Navigation';
Expand All @@ -32,9 +31,6 @@ function WorkspaceInvoicingDetailsWebsite({route}: WorkspaceInvoicingDetailsWebs
const {inputCallbackRef} = useAutoFocusInput();
const styles = useThemeStyles();
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [user] = useOnyx(ONYXKEYS.USER);
const defaultWebsiteExample = useMemo(() => getDefaultCompanyWebsite(session, user), [session, user]);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const submit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_INVOICES_COMPANY_WEBSITE_FORM>) => {
Expand All @@ -49,10 +45,11 @@ function WorkspaceInvoicingDetailsWebsite({route}: WorkspaceInvoicingDetailsWebs
const errors = ValidationUtils.getFieldRequiredErrors(values, [INPUT_IDS.COMPANY_WEBSITE]);

if (values.companyWebsite) {
if (!ValidationUtils.isValidWebsite(Str.sanitizeURL(values.companyWebsite, CONST.COMPANY_WEBSITE_DEFAULT_SCHEME))) {
const companyWebsite = Str.sanitizeURL(values.companyWebsite, CONST.COMPANY_WEBSITE_DEFAULT_SCHEME);
if (!ValidationUtils.isValidWebsite(companyWebsite)) {
errors.companyWebsite = translate('bankAccount.error.website');
} else {
const domain = Url.extractUrlDomain(values.companyWebsite);
const domain = Url.extractUrlDomain(companyWebsite);

if (!domain || !Str.isValidDomainName(domain)) {
errors.companyWebsite = translate('iou.invalidDomainError');
Expand Down Expand Up @@ -91,7 +88,7 @@ function WorkspaceInvoicingDetailsWebsite({route}: WorkspaceInvoicingDetailsWebs
label={translate('workspace.invoices.companyWebsite')}
accessibilityLabel={translate('workspace.invoices.companyWebsite')}
role={CONST.ROLE.PRESENTATION}
defaultValue={policy?.invoice?.companyWebsite ?? defaultWebsiteExample}
defaultValue={policy?.invoice?.companyWebsite}
ref={inputCallbackRef}
inputMode={CONST.INPUT_MODE.URL}
/>
Expand Down
Loading