Skip to content

Commit b44b436

Browse files
committed
Support empty file varaible value Huachao#322
1 parent 086e286 commit b44b436

4 files changed

Lines changed: 21 additions & 19 deletions

File tree

‎src/common/constants.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const AzureClouds: { [key: string]: { aad: string, arm: string, armAudien
7070

7171
export const CommentIdentifiersRegex: RegExp = /^\s*(#|\/{2})/;
7272

73-
export const FileVariableDefinitionRegex: RegExp = /^\s*@([^\s=]+)\s*=\s*(.+?)\s*$/;
73+
export const FileVariableDefinitionRegex: RegExp = /^\s*@([^\s=]+)\s*=\s*(.*?)\s*$/;
7474

7575
export const RequestVariableDefinitionWithNameRegexFactory = (name: string, flags?: string): RegExp =>
7676
new RegExp(`^\\s*(?:#{1,}|\\/{2,})\\s+@name\\s+(${name})\\s*$`, flags);

‎src/utils/httpVariableProviders/fileVariableProvider.ts‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,28 @@ export class FileVariableProvider implements HttpVariableProvider {
6969
const fileContent = document.getText();
7070
const fileHash = md5(fileContent);
7171
if (!this.cache.has(file) || fileHash !== this.fileMD5Hash.get(file)) {
72-
const regex = new RegExp(Constants.FileVariableDefinitionRegex, 'mg');
7372
const variables = new Map<string, FileVariableValue>();
74-
let match: RegExpExecArray | null;
75-
while (match = regex.exec(fileContent)) {
76-
const [, key, originalValue] = match;
77-
let value = "";
78-
let isPrevCharEscape = false;
79-
for (const currentChar of originalValue) {
80-
if (isPrevCharEscape) {
81-
isPrevCharEscape = false;
82-
value += this.escapee.get(currentChar) || currentChar;
83-
} else {
84-
if (currentChar === "\\") {
85-
isPrevCharEscape = true;
86-
continue;
73+
for (const line of fileContent.split(Constants.LineSplitterRegex)) {
74+
const regex = new RegExp(Constants.FileVariableDefinitionRegex, 'g');
75+
let match: RegExpExecArray | null;
76+
while (match = regex.exec(line)) {
77+
const [, key, originalValue] = match;
78+
let value = "";
79+
let isPrevCharEscape = false;
80+
for (const currentChar of originalValue) {
81+
if (isPrevCharEscape) {
82+
isPrevCharEscape = false;
83+
value += this.escapee.get(currentChar) || currentChar;
84+
} else {
85+
if (currentChar === "\\") {
86+
isPrevCharEscape = true;
87+
continue;
88+
}
89+
value += currentChar;
8790
}
88-
value += currentChar;
8991
}
92+
variables.set(key, { name: key, value });
9093
}
91-
variables.set(key, { name: key, value });
9294
}
9395
this.cache.set(file, [...variables.values()]);
9496
this.fileMD5Hash.set(file, fileHash);

‎src/views/httpResponseWebview.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ ${HttpResponseWebview.formatHeaders(response.headers)}`;
353353
}
354354

355355
private static isHeadRequest({ request: { method } }: { request: HttpRequest }): boolean {
356-
return !!(method?.toLowerCase() === 'head');
356+
return method.toLowerCase() === 'head';
357357
}
358358
}
359359

‎syntaxes/http.tmLanguage‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
</dict>
191191
</dict>
192192
<key>match</key>
193-
<string>^\s*(@)([^\s=]+)\s*=\s*(.+)\s*$</string>
193+
<string>^\s*(@)([^\s=]+)\s*=\s*(.*?)\s*$</string>
194194
<key>name</key>
195195
<string>http.filevariable</string>
196196
</dict>

0 commit comments

Comments
 (0)