From 0ec66ebae7de89cf6238bff92898dc5616173dd3 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sun, 21 Jan 2018 17:38:03 +0100 Subject: [PATCH] IPP: fix off-by-one error (IDEA-185274) --- ...ormatStringWithConcatenationIntention.java | 2 +- ...tStringWithConcatenationIntentionTest.java | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntention.java index 16f584459f8e..19eda4b64489 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntention.java @@ -112,7 +112,7 @@ public class ReplaceFormatStringWithConcatenationIntention extends Intention { start = end + 2; end = value.indexOf("%s", start); } - if (start < value.length() - 1) { + if (start < value.length()) { if (builder.length() > 0) { builder.append('+'); } diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntentionTest.java index c4ba8cc5994a..c0625d8f6bf8 100644 --- a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntentionTest.java +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntentionTest.java @@ -1,24 +1,10 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.siyeh.ipp.concatenation; import com.siyeh.ipp.IPPTestCase; -import junit.framework.TestCase; /** + * @see ReplaceFormatStringWithConcatenationIntention * @author Bas Leijdekkers */ public class ReplaceFormatStringWithConcatenationIntentionTest extends IPPTestCase { @@ -94,4 +80,18 @@ public class ReplaceFormatStringWithConcatenationIntentionTest extends IPPTestCa " }" + "}"); } + + public void testSingleCharacterSuffix() { + doTest("class Idempotent {" + + " String x() {" + + " return String./*_Replace 'String.format()' with concatenation*/format(\"%s.\", \"foo\");" + + " }" + + "}", + + "class Idempotent {" + + " String x() {" + + " return \"foo\" + \".\";" + + " }" + + "}"); + } } \ No newline at end of file