]> source.dussan.org Git - gitblit.git/commitdiff
Fix bug in diff view for filenames with non-ASCII characters (issue 128)
authorJames Moger <james.moger@gitblit.com>
Mon, 10 Sep 2012 20:25:10 +0000 (16:25 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 10 Sep 2012 20:25:10 +0000 (16:25 -0400)
docs/03_faq.mkd
docs/04_releases.mkd
src/com/gitblit/utils/GitBlitDiffFormatter.java
src/com/gitblit/utils/GitWebDiffFormatter.java
src/com/gitblit/utils/StringUtils.java

index 36be82bf434785cdcdd5ffc2de2fc66d6e6509c3..cdf3d59ef4739f818afc056ebf30ef2644d8d99a 100644 (file)
@@ -71,6 +71,13 @@ Add *-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true* to *CATALIN
 2. *web.mountParameters = false* and use non-pretty, parameterized urls\r
 3. *web.forwardSlashCharacter = !* which tells Gitblit to use **!** instead of **/**\r
 \r
+#### UTF-8 Filenames\r
+\r
+Tomcat also dislikes urls with non-ASCII characters. If your repositories have non-ASCII filenames you will have to modify your connector properties to allow UTF-8 encoded urls.  \r
+\r
+[Tomcat Character Encoding](http://wiki.apache.org/tomcat/FAQ/CharacterEncoding)  \r
+[Tomcat Connector Properties](http://tomcat.apache.org/tomcat-6.0-doc/config/http.html)\r
+\r
 ## General Interest Questions\r
 \r
 ### Gitblit?  What kind of name is that?\r
index db7815b2f26b4166fa9e8585044316aa511db27c..d7b598b9787847fe8dccb2a4f0a5c8739764fcd7 100644 (file)
@@ -9,6 +9,14 @@ If you are updating from an earlier release AND you have indexed branches with t
 \r
 **%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%) | [war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%) | [express](http://code.google.com/p/gitblit/downloads/detail?name=%EXPRESS%) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%) | [api](http://code.google.com/p/gitblit/downloads/detail?name=%API%)) based on [%JGIT%][jgit] &nbsp; *released %BUILDDATE%*\r
 \r
+#### fixes\r
+\r
+- Fixed bug in the diff view for filenames that have non-ASCII characters (issue 128)\r
+\r
+#### additions\r
+\r
+- added RedmineUserService (github/mallowlabs)\r
+\r
 #### changes\r
 \r
 - Emit a warning in the log file if running on a Tomcat-based servlet container which is unfriendly to %2F forward-slash url encoding AND Gitblit is configured to mount parameters with %2F forward-slash url encoding (Github/jpyeron, issue 126)\r
index e9fbf5288ec10a1d06eea54e6d0f93e12ff82e06..2966aa8a8f23850ef1849632392481d7406a85e8 100644 (file)
@@ -127,15 +127,24 @@ public class GitBlitDiffFormatter extends GitWebDiffFormatter {
                        } else if (line.startsWith("---") || line.startsWith("+++")) {\r
                                // skip --- +++ lines\r
                        } else if (line.startsWith("diff")) {\r
+                               line = StringUtils.convertOctal(line);\r
                                if (line.indexOf(oldnull) > -1) {\r
                                        // a is null, use b\r
                                        line = line.substring(("diff --git " + oldnull).length()).trim();\r
                                        // trim b/\r
-                                       line = line.substring(2);\r
+                                       line = line.substring(2).trim();\r
                                } else {\r
                                        // use a\r
-                                       line = line.substring("diff --git a/".length()).trim();\r
-                                       line = line.substring(0, line.indexOf(" b/")).trim();\r
+                                       line = line.substring("diff --git ".length()).trim();\r
+                                       line = line.substring(line.startsWith("\"a/") ? 3 : 2);                                 \r
+                                       line = line.substring(0, line.indexOf(" b/") > -1 ? line.indexOf(" b/") : line.indexOf("\"b/")).trim();\r
+                               }\r
+                               \r
+                               if (line.charAt(0) == '"') {\r
+                                       line = line.substring(1);\r
+                               }\r
+                               if (line.charAt(line.length() - 1) == '"') {\r
+                                       line = line.substring(0, line.length() - 1);\r
                                }\r
                                if (inFile) {\r
                                        sb.append("</tbody></table></div>\n");\r
index 50c6c724019f1bcfcba091d7e34fd7a7212abd31..e657dc58f0104a6f2acee82b1eccd9fb223952db 100644 (file)
@@ -106,10 +106,10 @@ public class GitWebDiffFormatter extends DiffFormatter {
                        throws IOException {\r
                switch (prefix) {\r
                case '+':\r
-                       os.write("<span class=\"diff add\">".getBytes());\r
+                       os.write("<span style=\"color:#008000;\">".getBytes());\r
                        break;\r
                case '-':\r
-                       os.write("<span class=\"diff remove\">".getBytes());\r
+                       os.write("<span style=\"color:#800000;\">".getBytes());\r
                        break;\r
                }\r
                os.write(prefix);\r
@@ -140,11 +140,11 @@ public class GitWebDiffFormatter extends DiffFormatter {
                sb.append("<div class=\"diff\">");\r
                for (String line : lines) {\r
                        if (line.startsWith("diff")) {\r
-                               sb.append("<div class=\"diff header\">").append(line).append("</div>");\r
+                               sb.append("<div class=\"diff header\">").append(StringUtils.convertOctal(line)).append("</div>");\r
                        } else if (line.startsWith("---")) {\r
-                               sb.append("<span class=\"diff remove\">").append(line).append("</span><br/>");\r
+                               sb.append("<span style=\"color:#800000;\">").append(StringUtils.convertOctal(line)).append("</span><br/>");\r
                        } else if (line.startsWith("+++")) {\r
-                               sb.append("<span class=\"diff add\">").append(line).append("</span><br/>");\r
+                               sb.append("<span style=\"color:#008000;\">").append(StringUtils.convertOctal(line)).append("</span><br/>");\r
                        } else {\r
                                sb.append(line).append('\n');\r
                        }\r
index 08fd497229ac8414d608baf1a6714851bb98e782..e4407901d97b9b072e18613aa9a85d78492f6d1d 100644 (file)
@@ -15,6 +15,7 @@
  */\r
 package com.gitblit.utils;\r
 \r
+import java.io.ByteArrayOutputStream;\r
 import java.io.UnsupportedEncodingException;\r
 import java.nio.ByteBuffer;\r
 import java.nio.CharBuffer;\r
@@ -624,4 +625,39 @@ public class StringUtils {
                }\r
                return url;\r
        }\r
+       \r
+       /**\r
+        * Converts a string with \nnn sequences into a UTF-8 encoded string.\r
+        * @param input\r
+        * @return\r
+        */\r
+       public static String convertOctal(String input) {\r
+               try {\r
+                       ByteArrayOutputStream bytes = new ByteArrayOutputStream();\r
+                       Pattern p = Pattern.compile("(\\\\\\d{3})");\r
+                       Matcher m = p.matcher(input);\r
+                       int i = 0;\r
+                       while (m.find()) {\r
+                               bytes.write(input.substring(i, m.start()).getBytes("UTF-8"));\r
+                               // replace octal encoded value\r
+                               // strip leading \ character\r
+                               String oct = m.group().substring(1);\r
+                               bytes.write(Integer.parseInt(oct, 8));\r
+                               i = m.end();                    \r
+                       }\r
+                       if (bytes.size() == 0) {\r
+                               // no octal matches\r
+                               return input;\r
+                       } else {\r
+                               if (i < input.length()) {\r
+                                       // add remainder of string\r
+                                       bytes.write(input.substring(i).getBytes("UTF-8"));\r
+                               }\r
+                       }\r
+                       return bytes.toString("UTF-8");\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+               return input;\r
+       }\r
 }
\ No newline at end of file