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

ACL DELUSER does not work correctly with UTF-8 Japanese characters #3178 #3179

Merged
merged 5 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions .github/workflows/stale-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 30 days this issue will be closed.'
stale-pr-message: 'Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.'
days-before-stale: 365
days-before-close: 30
days-before-stale: 30
days-before-close: 14
stale-issue-label: "status: feedback-reminder"
stale-pr-label: "status: feedback-reminder"
operations-per-run: 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public ClaimedMessagesOutput(RedisCodec<K, V> codec, K stream, boolean justId) {
@Override
public void set(ByteBuffer bytes) {
if (startId == null) {
startId = decodeAscii(bytes);
startId = decodeString(bytes);
return;
}

if (id == null) {
id = decodeAscii(bytes);
id = decodeString(bytes);
return;
}

Expand Down
15 changes: 4 additions & 11 deletions src/main/java/io/lettuce/core/output/CommandOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.lettuce.core.output;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.internal.LettuceAssert;
Expand Down Expand Up @@ -139,7 +140,7 @@ public void set(boolean value) {
* @param error Error message.
*/
public void setError(ByteBuffer error) {
this.error = decodeAscii(error);
this.error = decodeString(error);
}

/**
Expand Down Expand Up @@ -179,16 +180,8 @@ public void complete(int depth) {
// nothing to do by default
}

protected String decodeAscii(ByteBuffer bytes) {
if (bytes == null) {
return null;
}

char[] chars = new char[bytes.remaining()];
for (int i = 0; i < chars.length; i++) {
chars[i] = (char) bytes.get();
}
return new String(chars);
protected String decodeString(ByteBuffer bytes) {
return bytes == null ? null : StandardCharsets.UTF_8.decode(bytes).toString();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/output/DoubleListOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DoubleListOutput(RedisCodec<K, V> codec) {

@Override
public void set(ByteBuffer bytes) {
output.add(bytes != null ? parseDouble(decodeAscii(bytes)) : null);
output.add(bytes != null ? parseDouble(decodeString(bytes)) : null);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/output/DoubleOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DoubleOutput(RedisCodec<K, V> codec) {

@Override
public void set(ByteBuffer bytes) {
output = (bytes == null) ? null : parseDouble(decodeAscii(bytes));
output = (bytes == null) ? null : parseDouble(decodeString(bytes));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/output/EnumSetOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void set(ByteBuffer bytes) {
return;
}

E enumConstant = resolve(enumValuePreprocessor.apply(decodeAscii(bytes)));
E enumConstant = resolve(enumValuePreprocessor.apply(decodeString(bytes)));

if (enumConstant == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void set(ByteBuffer bytes) {
return;
}

double value = (bytes == null) ? 0 : parseDouble(decodeAscii(bytes));
double value = (bytes == null) ? 0 : parseDouble(decodeString(bytes));
set(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void set(ByteBuffer bytes) {
return;
}

double value = parseDouble(decodeAscii(bytes));
double value = parseDouble(decodeString(bytes));
set(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void set(ByteBuffer bytes) {
return;
}

double value = (bytes == null) ? 0 : parseDouble(decodeAscii(bytes));
double value = (bytes == null) ? 0 : parseDouble(decodeString(bytes));
set(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void set(ByteBuffer bytes) {
multi(1);
}

output.add(JsonType.fromString(decodeAscii(bytes)));
output.add(JsonType.fromString(decodeString(bytes)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void set(ByteBuffer bytes) {
value = codec.decodeValue(bytes);
return;
}
score = parseDouble(decodeAscii(bytes));
score = parseDouble(decodeString(bytes));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void set(ByteBuffer bytes) {
return;
}

output = KeyValue.just(key, ScoredValue.just(parseDouble(decodeAscii(bytes)), value));
output = KeyValue.just(key, ScoredValue.just(parseDouble(decodeString(bytes)), value));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void set(ByteBuffer bytes) {
return;
}

double score = LettuceStrings.toDouble(decodeAscii(bytes));
double score = LettuceStrings.toDouble(decodeString(bytes));

set(score);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/output/MultiOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void setError(ByteBuffer error) {
}

CommandOutput<K, V, ?> output = queue.isEmpty() ? this : queue.peek().getOutput();
output.setError(decodeAscii(error));
output.setError(decodeString(error));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/output/NumberListOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void multi(int count) {
private Number parseNumber(ByteBuffer bytes) {
Number result = 0;
try {
result = NumberFormat.getNumberInstance().parse(decodeAscii(bytes));
result = NumberFormat.getNumberInstance().parse(decodeString(bytes));
} catch (ParseException e) {
LOG.warn("Failed to parse " + bytes, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PendingMessageListOutput(RedisCodec<K, V> codec) {
public void set(ByteBuffer bytes) {

if (messageId == null) {
messageId = decodeAscii(bytes);
messageId = decodeString(bytes);
return;
}

Expand All @@ -51,7 +51,7 @@ public void set(ByteBuffer bytes) {
return;
}

set(Long.parseLong(decodeAscii(bytes)));
set(Long.parseLong(decodeString(bytes)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public PendingMessagesOutput(RedisCodec<K, V> codec) {
public void set(ByteBuffer bytes) {

if (messageIdsFrom == null) {
messageIdsFrom = decodeAscii(bytes);
messageIdsFrom = decodeString(bytes);
return;
}

if (messageIdsTo == null) {
messageIdsTo = decodeAscii(bytes);
messageIdsTo = decodeString(bytes);
return;
}

Expand All @@ -54,7 +54,7 @@ public void set(ByteBuffer bytes) {
return;
}

set(Long.parseLong(decodeAscii(bytes)));
set(Long.parseLong(decodeString(bytes)));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/output/ScanOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ScanOutput(RedisCodec<K, V> codec, T cursor) {
public void set(ByteBuffer bytes) {

if (output.getCursor() == null) {
output.setCursor(decodeAscii(bytes));
output.setCursor(decodeString(bytes));
if (LettuceStrings.isNotEmpty(output.getCursor()) && "0".equals(output.getCursor())) {
output.setFinished(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void set(ByteBuffer bytes) {
return;
}

double score = LettuceStrings.toDouble(decodeAscii(bytes));
double score = LettuceStrings.toDouble(decodeString(bytes));
set(score);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void set(ByteBuffer bytes) {
return;
}

double score = LettuceStrings.toDouble(decodeAscii(bytes));
double score = LettuceStrings.toDouble(decodeString(bytes));
set(score);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void setOutput(ByteBuffer bytes) {
return;
}

double score = LettuceStrings.toDouble(decodeAscii(bytes));
double score = LettuceStrings.toDouble(decodeString(bytes));
set(score);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void setOutput(ByteBuffer bytes) {
return;
}

double score = LettuceStrings.toDouble(decodeAscii(bytes));
double score = LettuceStrings.toDouble(decodeString(bytes));
set(score);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void set(ByteBuffer bytes) {
return;
}

double score = LettuceStrings.toDouble(decodeAscii(bytes));
double score = LettuceStrings.toDouble(decodeString(bytes));
set(score);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/output/SocketAddressOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public SocketAddressOutput(RedisCodec<K, V> codec) {
public void set(ByteBuffer bytes) {

if (!hasHostname) {
hostname = decodeAscii(bytes);
hostname = decodeString(bytes);
hasHostname = true;
return;
}

int port = Integer.parseInt(decodeAscii(bytes));
int port = Integer.parseInt(decodeString(bytes));
output = InetSocketAddress.createUnresolved(hostname, port);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/output/StatusOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public StatusOutput(RedisCodec<K, V> codec) {

@Override
public void set(ByteBuffer bytes) {
output = OK.equals(bytes) ? "OK" : decodeAscii(bytes);
output = OK.equals(bytes) ? "OK" : decodeString(bytes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public StreamMessageListOutput(RedisCodec<K, V> codec, K stream) {
public void set(ByteBuffer bytes) {

if (id == null) {
id = decodeAscii(bytes);
id = decodeString(bytes);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/output/StreamReadOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void set(ByteBuffer bytes) {
}

if (id == null) {
id = decodeAscii(bytes);
id = decodeString(bytes);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/output/StringListOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void set(ByteBuffer bytes) {
multi(1);
}

subscriber.onNext(output, bytes == null ? null : decodeAscii(bytes));
subscriber.onNext(output, bytes == null ? null : decodeString(bytes));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public StringValueListOutput(RedisCodec<K, V> codec) {

@Override
public void set(ByteBuffer bytes) {
subscriber.onNext(output, bytes == null ? Value.empty() : Value.fromNullable(decodeAscii(bytes)));
subscriber.onNext(output, bytes == null ? Value.empty() : Value.fromNullable(decodeString(bytes)));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/pubsub/PubSubOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void set(ByteBuffer bytes) {
}

if (type == null) {
type = Type.valueOf(decodeAscii(bytes));
type = Type.valueOf(decodeString(bytes));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
package io.lettuce.core.commands;

import static io.lettuce.TestTags.INTEGRATION_TEST;
import static java.util.Arrays.stream;
import static org.assertj.core.api.Assertions.*;

import javax.inject.Inject;

import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.test.resource.DefaultRedisClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand All @@ -43,6 +46,8 @@
import io.lettuce.test.LettuceExtension;
import io.lettuce.test.condition.EnabledOnCommand;

import java.util.List;

/**
* Integration tests for ACL commands.
*
Expand All @@ -64,9 +69,12 @@ protected AclCommandIntegrationTests(RedisCommands<String, String> redis) {

@BeforeEach
void setUp() {
redis.flushall();
redis.aclUsers().stream().filter(o -> !"default".equals(o)).forEach(redis::aclDeluser);
redis.aclLogReset();
try (StatefulRedisConnection<String, String> conn = DefaultRedisClient.get().connect(StringCodec.UTF8)) {
conn.sync().flushall();
List<String> users = conn.sync().aclUsers();
users.stream().filter(o -> !"default".equals(o)).forEach(redis::aclDeluser);
conn.sync().aclLogReset();
}
}

@Test
Expand Down Expand Up @@ -131,7 +139,7 @@ void aclLog() {

@Test
void aclList() {
assertThat(redis.aclList()).hasSize(2).first().asString().contains("user default");
assertThat(redis.aclList()).hasSize(1).first().asString().contains("user default");
}

@Test
Expand Down Expand Up @@ -161,7 +169,7 @@ void aclSetuserWithCategories() {

@Test
void aclUsers() {
assertThat(redis.aclUsers()).hasSize(2).first().isEqualTo("default");
assertThat(redis.aclUsers()).hasSize(1).first().isEqualTo("default");
}

@Test
Expand Down
Loading
Loading