From 9beae23d02a1e6b6b068d0b7df22b366b06e4873 Mon Sep 17 00:00:00 2001 From: Renlong Tu <5545529+SLdragon@users.noreply.github.com> Date: Thu, 2 Apr 2020 16:32:54 +0800 Subject: [PATCH] Update logic to valid env in repository url (#540) * Update logic to valid env in repository url * Update version * Update Co-authored-by: rentu --- package-lock.json | 2 +- package.json | 2 +- src/common/utility.ts | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 821917b4..b596d25e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "azure-iot-edge", - "version": "1.21.0-rc1", + "version": "1.21.0-rc2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 64272434..c12f0a67 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "azure-iot-edge", "displayName": "Azure IoT Edge", "description": "This extension is now a part of Azure IoT Tools extension pack. We highly recommend installing Azure IoT Tools to get full capabilities for Azure IoT development. Develop, deploy, debug, and manage your IoT Edge solution.", - "version": "1.21.0-rc1", + "version": "1.21.0-rc2", "publisher": "vsciot-vscode", "aiKey": "95b20d64-f54f-4de3-8ad5-165a75a6c6fe", "icon": "logo.png", diff --git a/src/common/utility.ts b/src/common/utility.ts index 5ab04780..1c617f37 100644 --- a/src/common/utility.ts +++ b/src/common/utility.ts @@ -160,7 +160,7 @@ export class Utility { } public static expandEnv(input: string, overrideKVs: {[name: string]: string} = {}, ...exceptKeys: string[]): string { - const pattern: RegExp = new RegExp(/\$([a-zA-Z0-9_]+)|\${([a-zA-Z0-9_]+)}/g); + const pattern: RegExp = new RegExp(/\$(\w+)|\${(\w+)}/g); const exceptSet: Set = new Set(exceptKeys); if (!overrideKVs) { overrideKVs = {}; @@ -586,20 +586,25 @@ export class Utility { hostName = null; } - if (hostName && /[^a-zA-Z0-9\.\-:\${}]/.test(hostName)) { - return "Repository host name can only contain alphanumeric characters or .-:, and ${} are also supported for environment variables"; + if (hostName) { + const hostNameWithoutEnv = hostName.replace(/\$\w+|\${\w+}/g, ""); + if (/[^\w.-:]/.test(hostNameWithoutEnv)) { + return "Repository host name can only contain alphanumeric characters or .-:, and ${} are also supported for environment variables"; + } } - if (/[^a-z0-9\._\-\/\${}]+/.test(repositoryName)) { + const repositoryNameWithoutEnv = repositoryName.replace(/\$\w+|\${\w+}/g, ""); + if (/[^a-z0-9._\-\/]+/.test(repositoryNameWithoutEnv)) { return "Repository name can only contain lowercase letters, digits or ._-/, and ${} are also supported for environment variables"; } if (tag) { - if (tag.length > 128) { + const tagWithoutEnv = tag.replace(/\$\w+|\${\w+}/g, ""); + if (tagWithoutEnv.length > 128) { return "The maximum length of tag is 128"; } - if (/[^a-zA-Z0-9\._\-\${}]+/.test(tag)) { + if (/[^\w.-]+/.test(tagWithoutEnv)) { return "Tag can only contain alphanumeric characters or ._-, and ${} are also supported for environment variables"; } }