Skip to content

Commit

Permalink
feat: check for null and added url string
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhsircar11 committed Jan 29, 2025
1 parent b0ebd20 commit 307c371
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions libs/blocks/locui-create/input-urls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export function validateUrls(urlsStr) {
const errorMessage = 'Invalid URL Pattern. Please enter valid URL';
while (urls.length > 0) {
try {
const url = new URL(urls[0]);
if (!(/^(https):\/\/[^\s/$.?#].[^\s]*$/g.test(urls[0]))) {
return errorMessage;
}
if (validateOrigin(url)) {
if (!validateOrigin(urls[0])) {
return errorMessage;
}
} catch {
Expand Down
8 changes: 5 additions & 3 deletions libs/blocks/locui-create/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,18 @@ export function validateOrigin(urlStr) {
try {
const url = new URL(urlStr);
const urlDomains = url.host?.split('.');
const originDomains = origin.host?.split('.');
if (urlDomains.length === originDomains.length) {
const originUrl = new URL(origin);
const originDomains = originUrl.host?.split('.');
if (urlDomains && originDomains && urlDomains.length === originDomains.length) {
const [urlSD, urlSDL, urlTDL] = urlDomains;
const [originSD, originSDL, originTDL] = originDomains;
if (urlSD === originSD && urlTDL === originTDL && (urlSDL === originSDL || urlSDL === 'aem' || urlSDL === 'hlx')) {
return true;
}
return false;
}
return false;
} catch {
} catch (e) {
return false;
}
}
5 changes: 3 additions & 2 deletions libs/blocks/locui/loc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import {
user,
} from '../utils/state.js';
import { setStatus } from '../utils/status.js';
import { getStatus, origin, preview } from '../utils/franklin.js';
import { getStatus, preview } from '../utils/franklin.js';
import login from '../../../tools/sharepoint/login.js';
import { getServiceUpdates } from '../utils/miloc.js';
import { connectSK } from '../../../utils/sidekick.js';
import { isUrl, getUrl } from '../utils/url.js';
import { validateOrigin } from '../../locui-create/utils/utils.js';

const LANG_ACTIONS = ['Translate', 'English Copy', 'Rollout', 'Transcreate'];
const MOCK_REFERRER = 'https%3A%2F%2Fadobe.sharepoint.com%2F%3Ax%3A%2Fr%2Fsites%2Fadobecom%2F_layouts%2F15%2FDoc.aspx%3Fsourcedoc%3D%257B94460FAC-CDEE-4B31-B8E0-AA5E3F45DCC5%257D%26file%3Dwesco-demo.xlsx';
Expand Down Expand Up @@ -48,7 +49,7 @@ export function validateUrlsFormat(projectUrls, removeMedia = false) {
projectUrls.forEach((projectUrl, idx) => {
const url = getUrl(projectUrl);
const domain = isUrl(url.alt) ?? url;
if (domain.origin !== origin) {
if (!validateOrigin(url)) {
const aemUrl = domain.hostname?.split('--').length === 3;
url.valid = !aemUrl ? 'not AEM url' : 'not same domain';
}
Expand Down

0 comments on commit 307c371

Please sign in to comment.