Skip to content

Commit

Permalink
Update logic to valid env in repository url (#540)
Browse files Browse the repository at this point in the history
* Update logic to valid env in repository url

* Update version

* Update

Co-authored-by: rentu <[email protected]>
  • Loading branch information
SLdragon and SLdragon authored Apr 2, 2020
1 parent 9003076 commit 9beae23
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 11 additions & 6 deletions src/common/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = new Set(exceptKeys);
if (!overrideKVs) {
overrideKVs = {};
Expand Down Expand Up @@ -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";
}
}
Expand Down

0 comments on commit 9beae23

Please sign in to comment.