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

fix: Revert "fix: Always make sure we put valid utf8-encoded strings into attribute values" #663

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 1 addition & 13 deletions app/src/main/java/io/appium/uiautomator2/utils/XMLHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import androidx.annotation.Nullable;

import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern;

public abstract class XMLHelpers {
Expand Down Expand Up @@ -51,18 +50,7 @@ public static String toNodeName(String str) {
@Nullable
public static String toSafeString(@Nullable Object source, String replacement) {
return source == null ? null : XML10_PATTERN
.matcher(toSafeUtf8String(String.valueOf(source)))
.matcher(String.valueOf(source))
.replaceAll(replacement);
}

@Nullable
public static String toSafeUtf8String(@Nullable String source) {
if (source == null) {
return null;
}

// This method always replaces malformed-input and unmappable-character sequences
// with this charset's default replacement byte array.
return new String(source.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

import static org.junit.Assert.assertEquals;

import static io.appium.uiautomator2.utils.XMLHelpers.toSafeString;

import android.os.SystemClock;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -240,12 +238,6 @@ private static List<Element> findNodesUsingXpath1(String xml, String xpathSelect
}
}

@Test
public void createsSafeXmlString() {
String text = toSafeString("°C\u000b", "?");
assertEquals(text, "°C?");
}

@Test
public void parsesComplexXpath1() {
String query = "(//android.widget.TextView[@text='some, text']/following::android.widget.ImageButton)[1]";
Expand Down
Loading