From notifications-return-5274-archive-asf-public=cust-asf.ponee.io@freemarker.incubator.apache.org Tue Mar 20 18:59:13 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 6D3A118067E for ; Tue, 20 Mar 2018 18:59:12 +0100 (CET) Received: (qmail 54733 invoked by uid 500); 20 Mar 2018 17:59:11 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 54724 invoked by uid 99); 20 Mar 2018 17:59:11 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Mar 2018 17:59:11 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 05C4C1A1743 for ; Tue, 20 Mar 2018 17:59:11 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.231 X-Spam-Level: X-Spam-Status: No, score=-4.231 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id EuAi6Nt1IArf for ; Tue, 20 Mar 2018 17:59:09 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id 338645F504 for ; Tue, 20 Mar 2018 17:59:09 +0000 (UTC) Received: (qmail 54641 invoked by uid 99); 20 Mar 2018 17:59:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Mar 2018 17:59:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4C47BF670B; Tue, 20 Mar 2018 17:59:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ddekany@apache.org To: notifications@freemarker.incubator.apache.org Date: Tue, 20 Mar 2018 17:59:09 -0000 Message-Id: <5671870d59e24fc3a5e3ebde5c82b6a8@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] incubator-freemarker git commit: Bug fixed: When string?split(separator) is called with "" as the argument, the string will be split to characters now. Earlier it has thrown an IllegalArgumentException (unless the r flag was specified). Bug fixed: When string?split(separator) is called with "" as the argument, the string will be split to characters now. Earlier it has thrown an IllegalArgumentException (unless the r flag was specified). Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/cb5f3276 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/cb5f3276 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/cb5f3276 Branch: refs/heads/2.3-gae Commit: cb5f3276ca3a3c45cfd6938921297030a0aa4b5f Parents: 470971a Author: ddekany Authored: Tue Mar 20 18:57:52 2018 +0100 Committer: ddekany Committed: Tue Mar 20 18:57:52 2018 +0100 ---------------------------------------------------------------------- .../core/BuiltInsForStringsBasic.java | 2 +- .../freemarker/template/utility/StringUtil.java | 55 ++++++++++++-------- src/manual/en_US/book.xml | 13 +++++ 3 files changed, 47 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb5f3276/src/main/java/freemarker/core/BuiltInsForStringsBasic.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/core/BuiltInsForStringsBasic.java b/src/main/java/freemarker/core/BuiltInsForStringsBasic.java index abb3530..27a6212 100644 --- a/src/main/java/freemarker/core/BuiltInsForStringsBasic.java +++ b/src/main/java/freemarker/core/BuiltInsForStringsBasic.java @@ -536,7 +536,7 @@ class BuiltInsForStringsBasic { long flags = argCnt > 1 ? RegexpHelper.parseFlagString((String) args.get(1)) : 0; String[] result = null; if ((flags & RegexpHelper.RE_FLAG_REGEXP) == 0) { - RegexpHelper.checkNonRegexpFlags("split", flags); + RegexpHelper.checkNonRegexpFlags(key, flags); result = StringUtil.split(s, splitString, (flags & RegexpHelper.RE_FLAG_CASE_INSENSITIVE) != 0); } else { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb5f3276/src/main/java/freemarker/template/utility/StringUtil.java ---------------------------------------------------------------------- diff --git a/src/main/java/freemarker/template/utility/StringUtil.java b/src/main/java/freemarker/template/utility/StringUtil.java index a5156aa..1238dd9 100644 --- a/src/main/java/freemarker/template/utility/StringUtil.java +++ b/src/main/java/freemarker/template/utility/StringUtil.java @@ -739,34 +739,45 @@ public class StringUtil { /** * Splits a string at the specified string. + * + * @param sep + * The string that separates the items of the resulting array. Since 2.3.28, if this is 0 length, then + * each character will be a separate item in the array. */ public static String[] split(String s, String sep, boolean caseInsensitive) { - String splitString = caseInsensitive ? sep.toLowerCase() : sep; - String input = caseInsensitive ? s.toLowerCase() : s; - int i, b, e; - int cnt; - String res[]; - int ln = s.length(); - int sln = sep.length(); + int sepLn = sep.length(); - if (sln == 0) throw new IllegalArgumentException( - "The separator string has 0 length"); + String convertedS = caseInsensitive ? s.toLowerCase() : s; + int sLn = s.length(); + + if (sepLn == 0) { + String[] res = new String[sLn]; + for (int i = 0; i < sLn; i++) { + res[i] = String.valueOf(s.charAt(i)); + } + return res; + } - i = 0; - cnt = 1; - while ((i = input.indexOf(splitString, i)) != -1) { - cnt++; - i += sln; + String splitString = caseInsensitive ? sep.toLowerCase() : sep; + String res[]; + + { + int next = 0; + int count = 1; + while ((next = convertedS.indexOf(splitString, next)) != -1) { + count++; + next += sepLn; + } + res = new String[count]; } - res = new String[cnt]; - i = 0; - b = 0; - while (b <= ln) { - e = input.indexOf(splitString, b); - if (e == -1) e = ln; - res[i++] = s.substring(b, e); - b = e + sln; + int dst = 0; + int next = 0; + while (next <= sLn) { + int end = convertedS.indexOf(splitString, next); + if (end == -1) end = sLn; + res[dst++] = s.substring(next, end); + next = end + sepLn; } return res; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb5f3276/src/manual/en_US/book.xml ---------------------------------------------------------------------- diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml index 349319c..eb4470f 100644 --- a/src/manual/en_US/book.xml +++ b/src/manual/en_US/book.xml @@ -14441,6 +14441,10 @@ foobar ?split(",", "r") in the last example the last "" would be missing from the output. + If the 1st parameter is an empty string, the string will be + split to characters (since FreeMarker 2.3.28 - earlier this has only + worked with the r flag). + To check if a strings ends with something and append it otherwise, use the @@ -27635,6 +27639,15 @@ TemplateModel x = env.getVariable("x"); // get variable x evaluated in the context of the called macro or function.) + + + Bug fixed: When + string?split(separator) + is called with "" as the argument, the string + will be split to characters now. Earlier it has thrown an + IllegalArgumentException (unless the + r flag was specified). +