[properties] support encoding detection of large property files IDEA-360552

GitOrigin-RevId: 4b8e53f97bc93df6c9b2b212b5fa3b92692773c1
This commit is contained in:
Aleksey Dobrynin
2024-10-14 16:01:29 +00:00
committed by intellij-monorepo-bot
parent fa240427fa
commit 4c68556fdc
2 changed files with 17 additions and 6 deletions
@@ -2,6 +2,7 @@
package com.intellij.compiler;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.registry.RegistryValue;
@@ -87,6 +88,21 @@ public class CompilerEncodingServiceTest extends JavaPsiTestCase {
assertEquals(StandardCharsets.ISO_8859_1, file.getCharset());
}
public void testBigPropertiesAutoEncoding() throws IOException {
final VirtualFile file = createFile("test.properties");
WriteAction.run(() -> {
@SuppressWarnings("NonAsciiCharacters")
byte[] bytes = "verifyEmail.tooltip=初回ログイン後またはアドレスの変更が送信された後に、ユーザーに自分の電子メールアドレスを確認するように要求します。\n"
.repeat(64).getBytes(StandardCharsets.UTF_8);
file.setBinaryContent(bytes);
});
LoadTextUtil.loadText(file, 1024);
assertEquals(StandardCharsets.UTF_8, file.getCharset());
}
public void testPropertiesEncodingFeatureFlagTest() {
RegistryValue registryValue = Registry.get("properties.file.encoding.legacy.support");
@@ -125,12 +125,7 @@ public final class CharsetUtil {
.onUnmappableCharacter(CodingErrorAction.REPORT)
.onMalformedInput(CodingErrorAction.REPORT);
CoderResult result = decoder.decode(byteBuffer, decodedBuffer, true);
if (result.isError()) {
return TextRange.from(byteBuffer.position(), result.length());
}
result = decoder.flush(decodedBuffer);
CoderResult result = decoder.decode(byteBuffer, decodedBuffer, false);
if (result.isError()) {
return TextRange.from(byteBuffer.position(), result.length());
}