1
0
mirror of https://github.com/redis/node-redis.git synced 2025-12-09 21:21:11 +03:00

Fix TAG field search with special characters in doctest

- Remove incorrect try-catch block that hid the real issue
- Add proper escaping for special characters (@ and .) in email address
- Use correct search syntax: @email:{escaped_value}
- Add assertion to verify the search returns 1 result
- Add explanatory comment about escaping

Co-authored-by: nkaradzhov <1475500+nkaradzhov@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-10-15 15:39:08 +00:00
parent 21490cf0f2
commit 9e7e6e10a4

View File

@@ -95,13 +95,12 @@ await client.ft.create('idx:email', {
await client.json.set('key:1', '$', { email: 'test@redis.com' });
try {
const res6 = await client.ft.search('idx:email', 'test@redis.com', { DIALECT: 2 });
console.log(res6);
} catch (err) {
console.log("'test@redis.com' syntax not yet supported.");
}
// Escape special characters (. and @) in the email address for TAG field search
const emailAddress = 'test@redis.com'.replace(/[.@\\]/g, '\\$&');
const res6 = await client.ft.search('idx:email', `@email:{${emailAddress}}`);
console.log(res6.total); // >>> 1
// REMOVE_START
assert.strictEqual(res6.total, 1);
await client.ft.dropIndex('idx:email', { DD: true });
// REMOVE_END
// STEP_END