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: filter invalid chars for gradle wrapper #1813

Merged
merged 1 commit into from
Apr 8, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;

Expand All @@ -29,6 +30,8 @@ public class ExportGradleProject {

private static final Logger LOG = LoggerFactory.getLogger(ExportGradleProject.class);

private static final Pattern ILLEGAL_GRADLE_CHARS = Pattern.compile("[/\\\\:>\"?*|]");

private static final Set<String> IGNORE_CLS_NAMES = new HashSet<>(Arrays.asList(
"R",
"BuildConfig"));
Expand Down Expand Up @@ -72,7 +75,7 @@ private void saveProjectBuildGradle() throws IOException {
private void saveSettingsGradle() throws IOException {
TemplateFile tmpl = TemplateFile.fromResources("/export/settings.gradle.tmpl");

tmpl.add("applicationName", applicationParams.getApplicationName());
tmpl.add("applicationName", ILLEGAL_GRADLE_CHARS.matcher(applicationParams.getApplicationName()).replaceAll(""));
tmpl.save(new File(projectDir, "settings.gradle"));
}

Expand Down
6 changes: 6 additions & 0 deletions jadx-core/src/test/java/jadx/tests/api/ExportGradleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ protected String getAppGradleBuild() {
assertThat(appBuildGradle.exists());
return loadFileContent(appBuildGradle);
}

protected String getSettingsGradle() {
File settingsGradle = new File(exportDir, "settings.gradle");
assertThat(settingsGradle.exists());
return loadFileContent(settingsGradle);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package jadx.tests.export;

import org.junit.jupiter.api.Test;

import jadx.tests.api.ExportGradleTest;

import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;

class IllegalCharsForGradleWrapper extends ExportGradleTest {

@Test
void test() {
exportGradle("IllegalCharsForGradleWrapper.xml", "strings.xml");

assertThat(getSettingsGradle()).contains("'JadxTestApp'");
}
}
6 changes: 6 additions & 0 deletions jadx-core/src/test/manifest/IllegalCharsForGradleWrapper.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" android:compileSdkVersion="33" android:compileSdkVersionCodename="13" package="jadx.test.app" platformBuildVersionCode="33" platformBuildVersionName="13">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="32"/>
<application android:label="JadxTestApp/\:?*|">
</application>
</manifest>