From aa9854840929ef823aef40383606cfe10f40cfb7 Mon Sep 17 00:00:00 2001 From: rbuj Date: Thu, 29 Aug 2019 23:42:40 +0200 Subject: java-utils: Remove blank spaces before reading package name Closes https://github.com/mate-desktop/engrampa/issues/291 Test: touch test.txt zip test.zip test.txt mv test.zip test.jar cat << EOF > HelloWorld.java package org.mate.tests; class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World"); } } EOF engrampa -a test.jar HelloWorld.java jar tf test.jar Output: test.txt org/mate/tests/HelloWorld.java --- src/java-utils.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/java-utils.c b/src/java-utils.c index 5b36a9c..ce77c8d 100644 --- a/src/java-utils.c +++ b/src/java-utils.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "java-utils.h" @@ -424,13 +425,23 @@ get_package_name_from_java_file (char *fname) int index = 0; while (read (cfile->fd, &ch, 1) == 1) { + if ((ch != ' ') && (ch != '\t')) + break; + } + do { if (ch == ';') break; - if (ch == '.') + if (ch == '.') { buffer[index++] = '/'; - else + } else if (isalnum (ch) != 0) { buffer[index++] = ch; - } + } else if ((ch == '_') || (ch == '$')) { + buffer[index++] = ch; + } else { + index = 0; + break; + } + } while (read (cfile->fd, &ch, 1) == 1); buffer[index] = 0; package = g_strdup (buffer); } -- cgit v1.2.1