Skip to content

Commit d19722e

Browse files
authored
v5,6: fix error on empty token (#89)
1 parent e6db1c1 commit d19722e

File tree

14 files changed

+85
-5
lines changed

14 files changed

+85
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Changelog
2+
## 5.3.0
3+
Task 6.3.1
4+
- Fix "name not supplied" on empty token ([#88](https://github.com/qetza/replacetokens-task/issues/88)).
5+
6+
Task 5.6.1
7+
- Fix "name not supplied" on empty token ([#88](https://github.com/qetza/replacetokens-task/issues/88)).
8+
29
## 5.3.0
310
Task 6.3.0
411
- Add `info` log level for parameter _missingVarLog_.

tasks/ReplaceTokensV5/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## 5.6.1
3+
- Fix "name not supplied" on empty token ([#88](https://github.com/qetza/replacetokens-task/issues/88)).
4+
25
## 5.6.0
36
- Add `info` action for parameter _actionOnMissing_.
47

tasks/ReplaceTokensV5/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ var replaceTokensInString = function (
258258
if (options.enableRecursion && names.includes(name)) throw new Error("recursion cycle with token '" + name + "'.");
259259

260260
// replace value
261-
let value: string = name in externalVariables || options.useAdditionalVariablesOnly ? externalVariables[name] : tl.getVariable(name);
261+
let value: string = name in externalVariables || options.useAdditionalVariablesOnly ? externalVariables[name] : name ? tl.getVariable(name) : undefined;
262262

263263
let usedDefaultValue: boolean = false;
264264
if (

tasks/ReplaceTokensV5/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 5,
1515
"Minor": 6,
16-
"Patch": 0
16+
"Patch": 1
1717
},
1818
"releaseNotes": "Migrate to Node10 handler (breaking change).<br/>Add Node16 handler.",
1919
"instanceNameFormat": "Replace tokens in $(targetFiles)",

tasks/ReplaceTokensV5/tests/L0.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,27 @@ describe('ReplaceTokens v5 L0 suite', function () {
12171217
actual.should.equal(expected, 'replaced output');
12181218
}, tr);
12191219
});
1220+
1221+
it('should treat empty token as mising variable', async () => {
1222+
// arrange
1223+
let tp = path.join(__dirname, 'targetFiles', 'L0_InlineReplace.js');
1224+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
1225+
1226+
process.env['__inputpath__'] = copyData('emptytoken.json', 'emptytoken.json');
1227+
1228+
// act
1229+
await tr.runAsync();
1230+
1231+
// assert
1232+
runValidation(() => {
1233+
tr.succeeded.should.equal(true, 'task succeeded');
1234+
1235+
tr.stdout.should.include('##vso[task.issue type=warning;source=TaskInternal;] variable not found: ');
1236+
tr.stdout.should.include('##vso[task.debug] : ');
1237+
1238+
assertFilesEqual(process.env['__inputpath__'], path.join(data, 'emptytoken.expected.json'), 'replaced output');
1239+
}, tr);
1240+
});
12201241
});
12211242

12221243
describe('external variables', function () {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"var1": "var1_value",
3+
"empty": ""
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"var1": "#{var1}#",
3+
"empty": "#{}#"
4+
}

tasks/ReplaceTokensV6/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## 6.3.1
3+
- Fix "name not supplied" on empty token ([#88](https://github.com/qetza/replacetokens-task/issues/88)).
4+
25
## 6.3.0
36
- Add `info` log level for parameter _missingVarLog_.
47

tasks/ReplaceTokensV6/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ async function run() {
154154
// replace tokens
155155
const result = await rt.replaceTokens(
156156
sources,
157-
(name: string) => (name in additionalVariables || useAdditionalVariablesOnly ? additionalVariables[name] : tl.getVariable(name)),
157+
(name: string) => (name in additionalVariables || useAdditionalVariablesOnly ? additionalVariables[name] : name ? tl.getVariable(name) : undefined),
158158
options
159159
);
160160

tasks/ReplaceTokensV6/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 6,
1515
"Minor": 3,
16-
"Patch": 0
16+
"Patch": 1
1717
},
1818
"releaseNotes": "breaking changes, see [changelog](https://github.com/qetza/replacetokens-task/blob/master/tasks/ReplaceTokensV6/CHANGELOG.md)",
1919
"instanceNameFormat": "Replace tokens",

0 commit comments

Comments
 (0)