Skip to content

Commit 050f5f6

Browse files
committed
fix(dev-env): make URL extraction less error-prone
1 parent e83022d commit 050f5f6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/commands/dev-env-sync-sql.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ function stripProtocol( url: string ): string {
4545
* @return Site home url. null if not found
4646
*/
4747
function findSiteHomeUrl( sql: string ): string | null {
48-
const regex = `['"](siteurl|home)['"],\\s?['"](.*?)['"]`;
49-
const url = sql.match( regex )?.[ 2 ] || '';
48+
const regex = /(['"])(?:siteurl|home)\1,\s?\1([Hh][Tt][Tt][Pp][Ss]?:\/\/.+?)\1/;
49+
const url = regex.exec( sql )?.[ 2 ] ?? '';
5050
try {
51-
new URL( url );
52-
return url;
51+
const parsed = new URL( url );
52+
return parsed.hostname ? url : null;
5353
} catch {
5454
return null;
5555
}

0 commit comments

Comments
 (0)