IPP: fix off-by-one error (IDEA-185274)

This commit is contained in:
Bas Leijdekkers
2018-01-21 17:39:32 +01:00
parent 84e4ac4c32
commit 0ec66ebae7
2 changed files with 17 additions and 17 deletions
@@ -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('+');
}
@@ -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\" + \".\";" +
" }" +
"}");
}
}