Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: coreutils.variables is now case insensitive for keys #65

Merged
merged 1 commit into from
Jun 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ingredient/ingredient-utils/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import {BakeVariable} from '@azbake/core'
import { DeploymentContext } from '@azbake/core';
import { BaseUtility} from '@azbake/core'

function stringCompareInsensitive(a: string, b: string) : boolean {
return a.localeCompare(b,undefined, {sensitivity: 'accent'}) === 0;
}


export class CoreUtils extends BaseUtility {

Expand Down Expand Up @@ -31,8 +35,20 @@ export class CoreUtils extends BaseUtility {
}
public async variable(key: string, def?: string): Promise<any> {
if (this.context.Config.variables) {
let v: BakeVariable = this.context.Config.variables.get(key) || new BakeVariable(def || "")
return await v.valueAsync(this.context)

//we want keys to be case insensitive, so we iterate all keys and find first case-insensitive match
//means there could be collisions, we don't care, and just use first found.

for(var variableKey in this.context.Config.variables){
if (stringCompareInsensitive(variableKey, key)) {

let v: BakeVariable = this.context.Config.variables.get(variableKey) || new BakeVariable(def || "")
return await v.valueAsync(this.context)
}
}

return new BakeVariable(def || "");

} else {
return ""
}
Expand Down