Skip to content

Commit 59a059c

Browse files
committed
Change character validation in tag key to align with server behavior
1 parent fd1103b commit 59a059c

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
55
## Upcoming Release
66

7+
Blob:
8+
9+
- Changed charaters validation against tag key in filtering blobs with tags to align with service side behavior. (issue #2561)
10+
711
## 2025.07 Version 3.35.0
812

913
General:

src/blob/persistence/QueryInterpreter/QueryParser.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,23 @@ class QueryParser {
314314
this.query.throw('expecting tag value');
315315
}
316316

317-
private ContainsInvalidTagKeyCharacter(key: string): boolean {
317+
private validateTagCharacter(key: string) {
318318
for (let c of key) {
319319
if (!(c >= 'a' && c <= 'z' ||
320320
c >= 'A' && c <= 'Z' ||
321321
c >= '0' && c <= '9' ||
322-
c == '_')) {
323-
return true;
322+
c == ' ' ||
323+
c == '+' ||
324+
c == '-' ||
325+
c == '.' ||
326+
c == '/' ||
327+
c == ':' ||
328+
c == '=' ||
329+
c == '_'
330+
)) {
331+
this.query.throw(`'${c}' not permitted in tag name or value`);
324332
}
325333
}
326-
return false;
327334
}
328335

329336
private validateKey(key: string) {
@@ -342,30 +349,14 @@ class QueryParser {
342349
if (!this.conditionHeader && ((key.length == 0) || (key.length > 128))) {
343350
this.query.throw('tag must be between 1 and 128 characters in length');
344351
}
345-
if (this.ContainsInvalidTagKeyCharacter(key)) {
346-
this.query.throw(`unexpected '${key}'`);
347-
}
352+
this.validateTagCharacter(key);
348353
}
349354

350355
private validateValue(value: string) {
351356
if (!this.conditionHeader && (value.length > 256)) {
352357
this.query.throw(`tag value must be between 0 and 256 characters in length`);
353358
}
354-
for (let c of value) {
355-
if (!(c >= 'a' && c <= 'z' ||
356-
c >= 'A' && c <= 'Z' ||
357-
c >= '0' && c <= '9' ||
358-
c == ' ' ||
359-
c == '+' ||
360-
c == '-' ||
361-
c == '.' ||
362-
c == '/' ||
363-
c == ':' ||
364-
c == '=' ||
365-
c == '_')) {
366-
this.query.throw(`'${c}' not permitted in tag name or value`);
367-
}
368-
}
359+
this.validateTagCharacter(value);
369360
}
370361

371362
/**

tests/blob/apis/blob.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,6 +2434,19 @@ describe("BlobAPIs", () => {
24342434
assert.deepStrictEqual(outputTags1, tags);
24352435
});
24362436

2437+
it("get blob tag with ifTags condition - key with special chars @loki @sql", async () => {
2438+
let tags: Tags = {
2439+
" key 1 +-.:=_/": '1a',
2440+
key2: 'a1'
2441+
};
2442+
await blobClient.setTags(tags);
2443+
2444+
let queryString = `" key 1 +-.:=_/"='1a'`;
2445+
let outputTags = (await blobClient.getTags({ conditions: { tagConditions: queryString } })).tags;
2446+
assert.deepStrictEqual(outputTags, tags);
2447+
});
2448+
2449+
24372450
it("get blob tag with long ifTags condition @loki @sql", async () => {
24382451
const tags = {
24392452
tag1: "val1",

0 commit comments

Comments
 (0)