Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev' into validatorFix
Browse files Browse the repository at this point in the history
  • Loading branch information
MoizAdnan authored Jun 27, 2024
2 parents b44204b + bc3cc91 commit 18ea6a5
Show file tree
Hide file tree
Showing 37 changed files with 932 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ const ProjectFields = ({
ProjectUpdateService.setSourceProjectName(project.name, '')
return
}
const valueRegex = new RegExp(`^${value}`, 'g')
let matchingCommit = commitData.find((data) => valueRegex.test(data.commitSHA))

let matchingCommit = commitData.find((data) => data.commitSHA.startsWith(value))
if (!matchingCommit) {
const commitResponse = (await ProjectService.checkUnfetchedCommit({
url: projectUpdateStatus.value.sourceURL,
Expand All @@ -251,7 +251,7 @@ const ProjectFields = ({
resolve(null)
}, 100)
})
matchingCommit = commitData.find((data) => valueRegex.test(data.commitSHA))
matchingCommit = commitData.find((data) => data.commitSHA.startsWith(value))
}
}
ProjectUpdateService.setSourceProjectName(project.name, matchingCommit?.projectName || '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ const locationTypeOptions = [
{ label: 'Showroom', value: 'showroom' }
]

export default function AddEditLocationModal({ location }: { location?: LocationType }) {
export default function AddEditLocationModal({
location,
sceneID
}: {
location?: LocationType
sceneID?: string | null
}) {
const { t } = useTranslation()

const locationMutation = useMutation(locationPath)
Expand All @@ -59,7 +65,8 @@ export default function AddEditLocationModal({ location }: { location?: Location

const name = useHookstate(location?.name || '')
const maxUsers = useHookstate(location?.maxUsersPerInstance || 20)
const scene = useHookstate(location?.sceneId || '')

const scene = useHookstate((location ? location.sceneId : sceneID) ?? '')
const videoEnabled = useHookstate<boolean>(location?.locationSetting.videoEnabled || true)
const audioEnabled = useHookstate<boolean>(location?.locationSetting.audioEnabled || true)
const screenSharingEnabled = useHookstate<boolean>(location?.locationSetting.screenSharingEnabled || true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ export default function AddEditProjectModal({
ProjectUpdateService.setSourceProjectName(project.name, '')
return
}
const valueRegex = new RegExp(`^${commitValue}`, 'g')
let matchingCommit = commitData.find((data) => valueRegex.test(data.commitSHA))

let matchingCommit = commitData.find((data) => data.commitSHA.startsWith(commitValue))
if (!matchingCommit) {
const commitResponse = (await ProjectService.checkUnfetchedCommit({
url: projectUpdateStatus.value.sourceURL,
Expand All @@ -187,7 +187,7 @@ export default function AddEditProjectModal({
resolve(null)
}, 100)
})
matchingCommit = commitData.find((data) => valueRegex.test(data.commitSHA))
matchingCommit = commitData.find((data) => data.commitSHA.startsWith(commitValue))
}
}
ProjectUpdateService.setSourceProjectName(project.name, matchingCommit?.projectName || '')
Expand Down
7 changes: 1 addition & 6 deletions packages/client-core/src/social/services/InviteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ Ethereal Engine. All Rights Reserved.
import { Paginated } from '@feathersjs/feathers'
import { useEffect } from 'react'

import {
EMAIL_REGEX,
INVITE_CODE_REGEX,
PHONE_REGEX,
USER_ID_REGEX
} from '@etherealengine/common/src/constants/IdConstants'
import { EMAIL_REGEX, INVITE_CODE_REGEX, PHONE_REGEX, USER_ID_REGEX } from '@etherealengine/common/src/regex'
import {
InviteCode,
InviteData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import InputCheck from '@etherealengine/client-core/src/common/components/InputC
import InputText from '@etherealengine/client-core/src/common/components/InputText'
import Menu from '@etherealengine/client-core/src/common/components/Menu'
import { NotificationService } from '@etherealengine/client-core/src/common/services/NotificationService'
import { EMAIL_REGEX, PHONE_REGEX } from '@etherealengine/common/src/constants/IdConstants'
import multiLogger from '@etherealengine/common/src/logger'
import { EMAIL_REGEX, PHONE_REGEX } from '@etherealengine/common/src/regex'
import { InviteCode, InviteData } from '@etherealengine/common/src/schema.type.module'
import { useMutableState } from '@etherealengine/hyperflux'
import { isShareAvailable } from '@etherealengine/spatial/src/common/functions/DetectFeatures'
Expand Down
9 changes: 6 additions & 3 deletions packages/client/pwa.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import { VitePWA } from 'vite-plugin-pwa'

import manifest from './manifest.default.json'

const WILDCARD_REGEX = /^\/.*$/
const LOCAL_FILESYSTEM_REGEX = /^\/@fs\/.*$/

/**
* Creates a new instance of the VitePWA plugin for Vite.js.
* @param {Object} clientSetting - An object containing custom settings for the PWA.
Expand Down Expand Up @@ -75,9 +78,9 @@ const PWA = (clientSetting) =>
// Allowlist all paths for navigateFallback during development
navigateFallbackAllowlist: [
// allow everything
new RegExp('^/.*$'),
WILDCARD_REGEX,
// allow @fs
new RegExp('^/@fs/.*$')
LOCAL_FILESYSTEM_REGEX
]
},
workbox: {
Expand All @@ -94,7 +97,7 @@ const PWA = (clientSetting) =>
// Allowlist all paths for navigateFallback during production
navigateFallbackAllowlist: [
// allow everything
new RegExp('^/.*$')
WILDCARD_REGEX
],
// Set the glob directory and patterns for the cache
globDirectory: process.env.APP_ENV === 'development' ? './public' : './dist',
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { EMAIL_REGEX } from './regex'

/**
* Config settings (for client and isomorphic engine usage).
*/
const localBuildOrDev =
globalThis.process.env.APP_ENV === 'development' || globalThis.process.env.VITE_LOCAL_BUILD === 'true'

// https://fightingforalostcause.net/content/misc/2006/compare-email-regex.php
const EMAIL_REGEX =
/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i

export function validateEmail(email: string): boolean {
return EMAIL_REGEX.test(email)
}
Expand Down
2 changes: 0 additions & 2 deletions packages/common/src/constants/AvatarConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,3 @@ export const THUMBNAIL_FILE_ALLOWED_EXTENSIONS = '.png,.jpg'
export const THUMBNAIL_WIDTH = 300
export const THUMBNAIL_HEIGHT = 300
export const MAX_ALLOWED_TRIANGLES = 100000
export const REGEX_VALID_URL =
/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g
3 changes: 0 additions & 3 deletions packages/common/src/constants/GitHubConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

export const GITHUB_URL_REGEX = /(?:git@|https:\/\/)([a-zA-Z0-9\-]+:[a-zA-Z0-9_]+@)?github.com[:/](.*)[.git]?/
export const GITHUB_PER_PAGE = 100
export const PUBLIC_SIGNED_REGEX = /https:\/\/[\w\d\s\-_]+:[\w\d\s\-_][email protected]\/([\w\d\s\-_]+)\/([\w\d\s\-_]+).git/
export const INSTALLATION_SIGNED_REGEX = /https:\/\/oauth2:[\w\d\s\-_][email protected]\/([\w\d\s\-_]+)\/([\w\d\s\-_]+).git/
30 changes: 0 additions & 30 deletions packages/common/src/constants/IdConstants.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/common/src/constants/ProjectKeyConstants.ts

This file was deleted.

135 changes: 135 additions & 0 deletions packages/common/src/regex/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
CPAL-1.0 License
The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.
The Original Code is Ethereal Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

// eslint-disable-next-line no-control-regex
export const INVALID_FILENAME_REGEX = /[_<>:"/\\|?*\u0000-\u001F]/g
export const WINDOWS_RESERVED_NAME_REGEX = /^(con|prn|aux|nul|com\d|lpt\d)$/i
export const VALID_SCENE_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9_\-\s]{1,62}[a-zA-Z0-9_\-]$/

/**
* Matches CSS imports & URLS.
* For eg: `@import "styles.css"`, `url(image.png)`. Captures the resource in group 2 or group 3.
*/
export const CSS_URL_REGEX = /(@import\s+["']([^"']+)["']|url\((?!['"]?(?:data):)['"]?([^'"\)]+)['"]?\))/gi

/**
* Matches absolute URLs. For eg: `http://example.com`, `https://example.com`, `ftp://example.com`, `//example.com`, etc.
* This Does NOT match relative URLs like `example.com`
*/
export const ABSOLUTE_URL_PROTOCOL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/

/**
* Captures project name and asset path from a URL.
* For eg: `/path/to/projects/project123/assets/images/logo.png` will capture following groups
* - `project123` => Group 1
* - `assets/images/logo.png` => Group 2
*/
export const STATIC_ASSET_REGEX = /^(?:.*\/(?:projects|static-resources)\/([^\/]*)\/((?:assets\/|).*)$)/

// =====================================================================
// ========================= ID Regex Patterns =========================
// =====================================================================

/**
* This regex is used to validate a string that conforms to the UUID version 4 format. It ensures that the string consists of exactly 32 hexadecimal digits arranged in the 8-4-4-4-12 pattern, separated by hyphens.
*/
export const USER_ID_REGEX = /^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/

/**
* Email regex. Source: https://fightingforalostcause.net/content/misc/2006/compare-email-regex.php
*/
export const EMAIL_REGEX =
/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i

/**
* This regex is useful for validating input that must be exactly 10 digits long, such as a phone number (without any separators or formatting).
*/
export const PHONE_REGEX = /^[0-9]{10}$/

/**
* This regex is used to validate strings that should consist of exactly 8 hexadecimal digits.
*/
export const INVITE_CODE_REGEX = /^[0-9a-fA-F]{8}$/

// =========================================================================
// ========================= GitHub Regex Patterns =========================
// =========================================================================

/**
* This regular expression is designed to match GitHub repository URLs in both SSH and HTTPS formats. Group 2 captures the owner and repository name.
* - For eg: `[email protected]:user/repo.git`
* - `user/repo` => Group 1
*/
export const GITHUB_URL_REGEX = /(?:[email protected]:|https:\/\/github.com\/)([a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+)(\.git)?$/

/**
* This regex is useful for extracting the owner and repository name from GitHub HTTPS URLs that contain authentication credentials in the URL itself. Group 1 captures the owner and Group 2 captures the repository name.
* - For eg: `https://username:[email protected]/owner/repository-name.git`
* - `owner` => Group 1
* - `repository-name` => Group 2
*/
export const PUBLIC_SIGNED_REGEX = /https:\/\/[\w\d\s\-_]+:[\w\d\s\-_][email protected]\/([\w\d\s\-_]+)\/([\w\d\s\-_]+).git$/

/**
* This regex is useful for extracting the owner and repository name from GitHub HTTPS URLs that contain OAuth2 token or credentials in the URL itself. Group 1 captures the owner and Group 2 captures the repository name.
* - For eg: `https://oauth2:[email protected]/owner/repository-name.git`
* - `owner` => Group 1
* - `repository-name` => Group 2
*/
export const INSTALLATION_SIGNED_REGEX = /https:\/\/oauth2:[\w\d\s\-_][email protected]\/([\w\d\s\-_]+)\/([\w\d\s\-_]+).git$/

// ==============================================================================
// ========================= Project Key Regex Patterns =========================
// ==============================================================================

/**
* This regex is used to match specific file paths or directory structures that start with `projects/`, followed by one or more valid characters (letters, digits, hyphens, underscores, or forward slashes), and end with `/assets/`
*/
export const ASSETS_REGEX = /projects\/[a-zA-Z0-9-_\/]+\/assets\//

/**
* This regex matches strings that start with `projects/`, followed by one or more characters that can be letters, digits, hyphens, underscores, or forward slashes.
*/
export const PROJECT_REGEX = /projects\/[a-zA-Z0-9-_\/]+/

/**
* This regex matches strings that start with `projects/`, followed by one or more characters that can be letters, digits, hyphens, underscores, or forward slashes, and then `/public/`.
*/
export const PROJECT_PUBLIC_REGEX = /projects\/[a-zA-Z0-9-_\/]+\/public\//

/**
* This regex matches strings that start with `projects/`, followed by one or more characters that can be letters, digits, hyphens, underscores, or forward slashes, and then `/thumbnails/`.
*/
export const PROJECT_THUMBNAIL_REGEX = /projects\/[a-zA-Z0-9-_\/]+\/thumbnails\//

export const VALID_PROJECT_NAME = /^(?!\s)[\w\-\s]+$/

// ==========================================================================
// ========================= Dynamic Regex Patterns =========================
// ==========================================================================

export const getCacheRegex = (fileServer: string) => {
return new RegExp(`${fileServer}\/projects`)
}
15 changes: 8 additions & 7 deletions packages/common/src/utils/validateSceneName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

// eslint-disable-next-line no-control-regex
const invalidFileNameRegex = /[_<>:"/\\|?*\u0000-\u001F]/g
const windowsReservedNameRegex = /^(con|prn|aux|nul|com\d|lpt\d)$/i
const validSceneNameRegex = /^[a-zA-Z0-9][a-zA-Z0-9_\-\s]{1,62}[a-zA-Z0-9_\-]$/
import {
INVALID_FILENAME_REGEX,
VALID_SCENE_NAME_REGEX,
WINDOWS_RESERVED_NAME_REGEX
} from '@etherealengine/common/src/regex'

export default function isValidSceneName(sceneName: string) {
return (
sceneName.length >= 3 &&
sceneName.length <= 64 &&
!invalidFileNameRegex.test(sceneName) &&
!windowsReservedNameRegex.test(sceneName) &&
validSceneNameRegex.test(sceneName)
!INVALID_FILENAME_REGEX.test(sceneName) &&
!WINDOWS_RESERVED_NAME_REGEX.test(sceneName) &&
VALID_SCENE_NAME_REGEX.test(sceneName)
)
}
Loading

0 comments on commit 18ea6a5

Please sign in to comment.