| 1 | /** | |
| 2 | * Diff Match and Patch | |
| 3 | * | |
| 4 | * Copyright 2006 Google Inc. | |
| 5 | * http://code.google.com/p/google-diff-match-patch/ | |
| 6 | * | |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 | * you may not use this file except in compliance with the License. | |
| 9 | * You may obtain a copy of the License at | |
| 10 | * | |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 | * | |
| 13 | * Unless required by applicable law or agreed to in writing, software | |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 16 | * See the License for the specific language governing permissions and | |
| 17 | * limitations under the License. | |
| 18 | */ | |
| 19 | package com.jsql.model.injection.strategy.blind.patch; | |
| 20 | ||
| 21 | import org.apache.commons.lang3.StringUtils; | |
| 22 | ||
| 23 | import java.util.*; | |
| 24 | import java.util.regex.Pattern; | |
| 25 | ||
| 26 | /* | |
| 27 | * Functions for diff, match and patch. | |
| 28 | * Computes the difference between two texts to create a patch. | |
| 29 | * Applies the patch onto another text, allowing for errors. | |
| 30 | * | |
| 31 | * @author fraser@google.com (Neil Fraser) | |
| 32 | */ | |
| 33 | ||
| 34 | /** | |
| 35 | * Class containing the diff, match and patch methods. | |
| 36 | * Also contains the behaviour settings. | |
| 37 | */ | |
| 38 | public class DiffMatchPatch { | |
| 39 | ||
| 40 | // Defaults. | |
| 41 | // Set these on your diff_match_patch instance to override the defaults. | |
| 42 | ||
| 43 | /** | |
| 44 | * Number of seconds to map a diff before giving up (0 for infinity). | |
| 45 | */ | |
| 46 | public static final float DIFF_TIMEOUT = 1.0f; | |
| 47 | ||
| 48 | /** | |
| 49 | * Cost of an empty edit operation in terms of edit characters. | |
| 50 | */ | |
| 51 | public static final short DIFF_EDIT_COST = 4; | |
| 52 | ||
| 53 | // Define some regex patterns for matching boundaries. | |
| 54 | private static final Pattern BLANK_LINE_END = Pattern.compile("\\n\\r?\\n\\Z", Pattern.DOTALL); | |
| 55 | private static final Pattern BLANK_LINE_START = Pattern.compile("\\A\\r?\\n\\r?\\n", Pattern.DOTALL); | |
| 56 | ||
| 57 | /** | |
| 58 | * Internal class for returning results from diff_linesToChars(). | |
| 59 | * Other less paranoid languages just use a three-element array. | |
| 60 | */ | |
| 61 | protected record LinesToCharsResult(String chars1, String chars2, List<String> lineArray) {} | |
| 62 | ||
| 63 | // DIFF FUNCTIONS | |
| 64 | ||
| 65 | /** | |
| 66 | * The data structure representing a diff is a Linked list of Diff objects: | |
| 67 | * {Diff(Operation.DELETE, "Hello"), Diff(Operation.INSERT, "Goodbye"), | |
| 68 | * Diff(Operation.EQUAL, " world.")} | |
| 69 | * which means: delete "Hello", add "Goodbye" and keep " world." | |
| 70 | */ | |
| 71 | public enum Operation { | |
| 72 | DELETE, INSERT, EQUAL | |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Find the differences between two texts. | |
| 77 | * @param text1 Old string to be diffed. | |
| 78 | * @param text2 New string to be diffed. | |
| 79 | * @param checklines Speedup flag. If false, then don't run a | |
| 80 | * line-level diff first to identify the changed areas. | |
| 81 | * If true, then run a faster slightly less optimal diff. | |
| 82 | * @return Linked List of Diff objects. | |
| 83 | */ | |
| 84 | public LinkedList<Diff> diffMain(String text1, String text2, boolean checklines) { | |
| 85 | // Set a deadline by which time the diff must be complete. | |
| 86 |
1
1. diffMain : Replaced long addition with subtraction → NO_COVERAGE |
long deadline = System.currentTimeMillis() + (long) (DiffMatchPatch.DIFF_TIMEOUT * 1000); |
| 87 |
1
1. diffMain : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffMain → NO_COVERAGE |
return this.diffMain(text1, text2, checklines, deadline); |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * Find the differences between two texts. Simplifies the problem by | |
| 92 | * stripping any common prefix or suffix off the texts before diffing. | |
| 93 | * @param valueText1 Old string to be diffed. | |
| 94 | * @param valueText2 New string to be diffed. | |
| 95 | * @param checklines Speedup flag. If false, then don't run a | |
| 96 | * line-level diff first to identify the changed areas. | |
| 97 | * If true, then run a faster slightly less optimal diff. | |
| 98 | * @param deadline Time when the diff should be complete by. Used | |
| 99 | * internally for recursive calls. Users should set DiffTimeout instead. | |
| 100 | * @return Linked List of Diff objects. | |
| 101 | */ | |
| 102 | private LinkedList<Diff> diffMain(String valueText1, String valueText2, boolean checklines, long deadline) { | |
| 103 | String text1 = valueText1; | |
| 104 | String text2 = valueText2; | |
| 105 | ||
| 106 | // Check for null inputs. | |
| 107 |
2
1. diffMain : negated conditional → NO_COVERAGE 2. diffMain : negated conditional → NO_COVERAGE |
if (text1 == null || text2 == null) { |
| 108 | throw new IllegalArgumentException("Null inputs. (diff_main)"); | |
| 109 | } | |
| 110 | ||
| 111 | // Check for equality (speedup). | |
| 112 | LinkedList<Diff> diffs; | |
| 113 |
1
1. diffMain : negated conditional → NO_COVERAGE |
if (text1.equals(text2)) { |
| 114 | diffs = new LinkedList<>(); | |
| 115 |
1
1. diffMain : negated conditional → NO_COVERAGE |
if (!text1.isEmpty()) { |
| 116 | diffs.add(new Diff(Operation.EQUAL, text1)); | |
| 117 | } | |
| 118 |
1
1. diffMain : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffMain → NO_COVERAGE |
return diffs; |
| 119 | } | |
| 120 | ||
| 121 | // Trim off common prefix (speedup). | |
| 122 | int commonlength = this.diffCommonPrefix(text1, text2); | |
| 123 | String commonprefix = text1.substring(0, commonlength); | |
| 124 | text1 = text1.substring(commonlength); | |
| 125 | text2 = text2.substring(commonlength); | |
| 126 | ||
| 127 | // Trim off common suffix (speedup). | |
| 128 | commonlength = this.diffCommonSuffix(text1, text2); | |
| 129 |
1
1. diffMain : Replaced integer subtraction with addition → NO_COVERAGE |
String commonsuffix = text1.substring(text1.length() - commonlength); |
| 130 |
1
1. diffMain : Replaced integer subtraction with addition → NO_COVERAGE |
text1 = text1.substring(0, text1.length() - commonlength); |
| 131 |
1
1. diffMain : Replaced integer subtraction with addition → NO_COVERAGE |
text2 = text2.substring(0, text2.length() - commonlength); |
| 132 | ||
| 133 | // Compute the diff on the middle block. | |
| 134 | diffs = this.diffCompute(text1, text2, checklines, deadline); | |
| 135 | ||
| 136 | // Restore the prefix and suffix. | |
| 137 |
1
1. diffMain : negated conditional → NO_COVERAGE |
if (!commonprefix.isEmpty()) { |
| 138 |
1
1. diffMain : removed call to java/util/LinkedList::addFirst → NO_COVERAGE |
diffs.addFirst(new Diff(Operation.EQUAL, commonprefix)); |
| 139 | } | |
| 140 |
1
1. diffMain : negated conditional → NO_COVERAGE |
if (!commonsuffix.isEmpty()) { |
| 141 |
1
1. diffMain : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
diffs.addLast(new Diff(Operation.EQUAL, commonsuffix)); |
| 142 | } | |
| 143 | ||
| 144 |
1
1. diffMain : removed call to com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupMerge → NO_COVERAGE |
this.diffCleanupMerge(diffs); |
| 145 |
1
1. diffMain : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffMain → NO_COVERAGE |
return diffs; |
| 146 | } | |
| 147 | ||
| 148 | /** | |
| 149 | * Find the differences between two texts. Assumes that the texts do not | |
| 150 | * have any common prefix or suffix. | |
| 151 | * @param text1 Old string to be diffed. | |
| 152 | * @param text2 New string to be diffed. | |
| 153 | * @param checklines Speedup flag. If false, then don't run a | |
| 154 | * line-level diff first to identify the changed areas. | |
| 155 | * If true, then run a faster slightly less optimal diff. | |
| 156 | * @param deadline Time when the diff should be complete by. | |
| 157 | * @return Linked List of Diff objects. | |
| 158 | */ | |
| 159 | private LinkedList<Diff> diffCompute(String text1, String text2, boolean checklines, long deadline) { | |
| 160 | LinkedList<Diff> diffs = new LinkedList<>(); | |
| 161 | ||
| 162 |
1
1. diffCompute : negated conditional → NO_COVERAGE |
if (text1.isEmpty()) { |
| 163 | // Just add some text (speedup). | |
| 164 | diffs.add(new Diff(Operation.INSERT, text2)); | |
| 165 |
1
1. diffCompute : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCompute → NO_COVERAGE |
return diffs; |
| 166 | } | |
| 167 | ||
| 168 |
1
1. diffCompute : negated conditional → NO_COVERAGE |
if (text2.isEmpty()) { |
| 169 | // Just delete some text (speedup). | |
| 170 | diffs.add(new Diff(Operation.DELETE, text1)); | |
| 171 |
1
1. diffCompute : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCompute → NO_COVERAGE |
return diffs; |
| 172 | } | |
| 173 | ||
| 174 | { | |
| 175 | // New scope to garbage collect longtext and shorttext. | |
| 176 |
2
1. diffCompute : changed conditional boundary → NO_COVERAGE 2. diffCompute : negated conditional → NO_COVERAGE |
String longtext = text1.length() > text2.length() ? text1 : text2; |
| 177 |
2
1. diffCompute : changed conditional boundary → NO_COVERAGE 2. diffCompute : negated conditional → NO_COVERAGE |
String shorttext = text1.length() > text2.length() ? text2 : text1; |
| 178 | int i = longtext.indexOf(shorttext); | |
| 179 |
1
1. diffCompute : negated conditional → NO_COVERAGE |
if (i != -1) { |
| 180 | // Shorter text is inside the longer text (speedup). | |
| 181 |
2
1. diffCompute : negated conditional → NO_COVERAGE 2. diffCompute : changed conditional boundary → NO_COVERAGE |
Operation op = (text1.length() > text2.length()) ? |
| 182 | Operation.DELETE : Operation.INSERT; | |
| 183 | diffs.add(new Diff(op, longtext.substring(0, i))); | |
| 184 | diffs.add(new Diff(Operation.EQUAL, shorttext)); | |
| 185 |
1
1. diffCompute : Replaced integer addition with subtraction → NO_COVERAGE |
diffs.add(new Diff(op, longtext.substring(i + shorttext.length()))); |
| 186 |
1
1. diffCompute : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCompute → NO_COVERAGE |
return diffs; |
| 187 | } | |
| 188 | ||
| 189 |
1
1. diffCompute : negated conditional → NO_COVERAGE |
if (shorttext.length() == 1) { |
| 190 | // Single character string. | |
| 191 | // After the previous speedup, the character can't be an equality. | |
| 192 | diffs.add(new Diff(Operation.DELETE, text1)); | |
| 193 | diffs.add(new Diff(Operation.INSERT, text2)); | |
| 194 |
1
1. diffCompute : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCompute → NO_COVERAGE |
return diffs; |
| 195 | } | |
| 196 | } | |
| 197 | ||
| 198 | // Check to see if the problem can be split in two. | |
| 199 | String[] hm = this.diffHalfMatch(text1, text2); | |
| 200 |
1
1. diffCompute : negated conditional → NO_COVERAGE |
if (hm != null) { |
| 201 | // A half-match was found, sort out the return data. | |
| 202 | String text1A = hm[0]; | |
| 203 | String text1B = hm[1]; | |
| 204 | String text2A = hm[2]; | |
| 205 | String text2B = hm[3]; | |
| 206 | String midCommon = hm[4]; | |
| 207 | // Send both pairs off for separate processing. | |
| 208 | LinkedList<Diff> diffsA = this.diffMain(text1A, text2A, checklines, deadline); | |
| 209 | List<Diff> diffsB = this.diffMain(text1B, text2B, checklines, deadline); | |
| 210 | // Merge the results. | |
| 211 | diffs = diffsA; | |
| 212 | diffs.add(new Diff(Operation.EQUAL, midCommon)); | |
| 213 | diffs.addAll(diffsB); | |
| 214 |
1
1. diffCompute : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCompute → NO_COVERAGE |
return diffs; |
| 215 | } | |
| 216 | ||
| 217 |
5
1. diffCompute : negated conditional → NO_COVERAGE 2. diffCompute : negated conditional → NO_COVERAGE 3. diffCompute : negated conditional → NO_COVERAGE 4. diffCompute : changed conditional boundary → NO_COVERAGE 5. diffCompute : changed conditional boundary → NO_COVERAGE |
if (checklines && text1.length() > 100 && text2.length() > 100) { |
| 218 |
1
1. diffCompute : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCompute → NO_COVERAGE |
return this.diffLineMode(text1, text2, deadline); |
| 219 | } | |
| 220 | ||
| 221 |
1
1. diffCompute : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCompute → NO_COVERAGE |
return this.diffBisect(text1, text2, deadline); |
| 222 | } | |
| 223 | ||
| 224 | /** | |
| 225 | * Do a quick line-level diff on both strings, then rediff the parts for | |
| 226 | * greater accuracy. | |
| 227 | * This speedup can produce non-minimal diffs. | |
| 228 | * @param valueText1 Old string to be diffed. | |
| 229 | * @param valueText2 New string to be diffed. | |
| 230 | * @param deadline Time when the diff should be complete by. | |
| 231 | * @return Linked List of Diff objects. | |
| 232 | */ | |
| 233 | private LinkedList<Diff> diffLineMode(String valueText1, String valueText2, long deadline) { | |
| 234 | // Scan the text on a line-by-line basis first. | |
| 235 | LinesToCharsResult b = this.diffLinesToChars(valueText1, valueText2); | |
| 236 | String text1 = b.chars1; | |
| 237 | String text2 = b.chars2; | |
| 238 | List<String> linearray = b.lineArray; | |
| 239 | ||
| 240 | LinkedList<Diff> diffs = this.diffMain(text1, text2, false, deadline); | |
| 241 | ||
| 242 | // Convert the diff back to original text. | |
| 243 |
1
1. diffLineMode : removed call to com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCharsToLines → NO_COVERAGE |
this.diffCharsToLines(diffs, linearray); |
| 244 | // Eliminate freak matches (e.g. blank lines) | |
| 245 |
1
1. diffLineMode : removed call to com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupSemantic → NO_COVERAGE |
this.diffCleanupSemantic(diffs); |
| 246 | ||
| 247 | // Rediff any replacement blocks, this time character-by-character. | |
| 248 | // Add a dummy entry at the end. | |
| 249 | diffs.add(new Diff(Operation.EQUAL, StringUtils.EMPTY)); | |
| 250 | int countDelete = 0; | |
| 251 | int countInsert = 0; | |
| 252 | StringBuilder textDelete = new StringBuilder(); | |
| 253 | StringBuilder textInsert = new StringBuilder(); | |
| 254 | ListIterator<Diff> pointer = diffs.listIterator(); | |
| 255 | Diff thisDiff = pointer.next(); | |
| 256 | ||
| 257 |
1
1. diffLineMode : negated conditional → NO_COVERAGE |
while (thisDiff != null) { |
| 258 | switch (thisDiff.getOperation()) { | |
| 259 | case INSERT: | |
| 260 |
1
1. diffLineMode : Changed increment from 1 to -1 → NO_COVERAGE |
countInsert++; |
| 261 | textInsert.append(thisDiff.getText()); | |
| 262 | break; | |
| 263 | case DELETE: | |
| 264 |
1
1. diffLineMode : Changed increment from 1 to -1 → NO_COVERAGE |
countDelete++; |
| 265 | textDelete.append(thisDiff.getText()); | |
| 266 | break; | |
| 267 | case EQUAL: | |
| 268 | // Upon reaching an equality, check for prior redundancies. | |
| 269 |
4
1. diffLineMode : negated conditional → NO_COVERAGE 2. diffLineMode : negated conditional → NO_COVERAGE 3. diffLineMode : changed conditional boundary → NO_COVERAGE 4. diffLineMode : changed conditional boundary → NO_COVERAGE |
if (countDelete >= 1 && countInsert >= 1) { |
| 270 | // Delete the offending records and add the merged ones. | |
| 271 | pointer.previous(); | |
| 272 |
3
1. diffLineMode : changed conditional boundary → NO_COVERAGE 2. diffLineMode : Replaced integer addition with subtraction → NO_COVERAGE 3. diffLineMode : negated conditional → NO_COVERAGE |
for (int j = 0; j < countDelete + countInsert; j++) { |
| 273 | pointer.previous(); | |
| 274 |
1
1. diffLineMode : removed call to java/util/ListIterator::remove → NO_COVERAGE |
pointer.remove(); |
| 275 | } | |
| 276 | for (Diff newDiff : this.diffMain(textDelete.toString(), textInsert.toString(), false, deadline)) { | |
| 277 |
1
1. diffLineMode : removed call to java/util/ListIterator::add → NO_COVERAGE |
pointer.add(newDiff); |
| 278 | } | |
| 279 | } | |
| 280 | countInsert = 0; | |
| 281 | countDelete = 0; | |
| 282 |
1
1. diffLineMode : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
textDelete.setLength(0); |
| 283 |
1
1. diffLineMode : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
textInsert.setLength(0); |
| 284 | break; | |
| 285 | } | |
| 286 |
1
1. diffLineMode : negated conditional → NO_COVERAGE |
thisDiff = pointer.hasNext() ? pointer.next() : null; |
| 287 | } | |
| 288 | diffs.removeLast(); // Remove the dummy entry at the end. | |
| 289 | ||
| 290 |
1
1. diffLineMode : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffLineMode → NO_COVERAGE |
return diffs; |
| 291 | } | |
| 292 | ||
| 293 | /** | |
| 294 | * Find the 'middle snake' of a diff, split the problem in two | |
| 295 | * and return the recursively constructed diff. | |
| 296 | * See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations. | |
| 297 | * @param text1 Old string to be diffed. | |
| 298 | * @param text2 New string to be diffed. | |
| 299 | * @param deadline Time at which to bail if not yet complete. | |
| 300 | * @return LinkedList of Diff objects. | |
| 301 | */ | |
| 302 | protected LinkedList<Diff> diffBisect(String text1, String text2, long deadline) { | |
| 303 | // Cache the text lengths to prevent multiple calls. | |
| 304 | int text1Length = text1.length(); | |
| 305 | int text2Length = text2.length(); | |
| 306 |
3
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 2. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 3. diffBisect : Replaced integer division with multiplication → NO_COVERAGE |
int maxD = (text1Length + text2Length + 1) / 2; |
| 307 |
1
1. diffBisect : Replaced integer multiplication with division → NO_COVERAGE |
int vLength = 2 * maxD; |
| 308 | int[] v1 = new int[vLength]; | |
| 309 | int[] v2 = new int[vLength]; | |
| 310 |
2
1. diffBisect : changed conditional boundary → NO_COVERAGE 2. diffBisect : negated conditional → NO_COVERAGE |
for (int x = 0; x < vLength; x++) { |
| 311 | v1[x] = -1; | |
| 312 | v2[x] = -1; | |
| 313 | } | |
| 314 |
1
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE |
v1[maxD + 1] = 0; |
| 315 |
1
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE |
v2[maxD + 1] = 0; |
| 316 |
1
1. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
int delta = text1Length - text2Length; |
| 317 | // If the total number of characters is odd, then the front path will | |
| 318 | // collide with the reverse path. | |
| 319 |
2
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : Replaced integer modulus with multiplication → NO_COVERAGE |
boolean front = delta % 2 != 0; |
| 320 | // Offsets for start and end of k loop. | |
| 321 | // Prevents mapping of space beyond the grid. | |
| 322 | int k1start = 0; | |
| 323 | int k1end = 0; | |
| 324 | int k2start = 0; | |
| 325 | int k2end = 0; | |
| 326 | ||
| 327 |
2
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : changed conditional boundary → NO_COVERAGE |
for (int d = 0; d < maxD; d++) { |
| 328 | // Bail out if deadline is reached. | |
| 329 |
2
1. diffBisect : changed conditional boundary → NO_COVERAGE 2. diffBisect : negated conditional → NO_COVERAGE |
if (System.currentTimeMillis() > deadline) { |
| 330 | break; | |
| 331 | } | |
| 332 | ||
| 333 | // Walk the front path one step. | |
| 334 |
5
1. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE 2. diffBisect : changed conditional boundary → NO_COVERAGE 3. diffBisect : removed negation → NO_COVERAGE 4. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 5. diffBisect : negated conditional → NO_COVERAGE |
for (int k1 = -d + k1start; k1 <= d - k1end; k1 += 2) { |
| 335 |
1
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE |
int k1Offset = maxD + k1; |
| 336 | int x1; | |
| 337 |
7
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 3. diffBisect : changed conditional boundary → NO_COVERAGE 4. diffBisect : negated conditional → NO_COVERAGE 5. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE 6. diffBisect : removed negation → NO_COVERAGE 7. diffBisect : negated conditional → NO_COVERAGE |
if (k1 == -d || (k1 != d && v1[k1Offset - 1] < v1[k1Offset + 1])) { |
| 338 |
1
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE |
x1 = v1[k1Offset + 1]; |
| 339 | } else { | |
| 340 |
2
1. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE 2. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE |
x1 = v1[k1Offset - 1] + 1; |
| 341 | } | |
| 342 |
1
1. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
int y1 = x1 - k1; |
| 343 |
4
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : changed conditional boundary → NO_COVERAGE 3. diffBisect : changed conditional boundary → NO_COVERAGE 4. diffBisect : negated conditional → NO_COVERAGE |
while (x1 < text1Length && y1 < text2Length |
| 344 |
1
1. diffBisect : negated conditional → NO_COVERAGE |
&& text1.charAt(x1) == text2.charAt(y1)) { |
| 345 |
1
1. diffBisect : Changed increment from 1 to -1 → NO_COVERAGE |
x1++; |
| 346 |
1
1. diffBisect : Changed increment from 1 to -1 → NO_COVERAGE |
y1++; |
| 347 | } | |
| 348 | v1[k1Offset] = x1; | |
| 349 |
2
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : changed conditional boundary → NO_COVERAGE |
if (x1 > text1Length) { |
| 350 | // Ran off the right of the graph. | |
| 351 |
1
1. diffBisect : Changed increment from 2 to -2 → NO_COVERAGE |
k1end += 2; |
| 352 |
2
1. diffBisect : changed conditional boundary → NO_COVERAGE 2. diffBisect : negated conditional → NO_COVERAGE |
} else if (y1 > text2Length) { |
| 353 | // Ran off the bottom of the graph. | |
| 354 |
1
1. diffBisect : Changed increment from 2 to -2 → NO_COVERAGE |
k1start += 2; |
| 355 |
1
1. diffBisect : negated conditional → NO_COVERAGE |
} else if (front) { |
| 356 |
2
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 2. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
int k2Offset = maxD + delta - k1; |
| 357 |
5
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : negated conditional → NO_COVERAGE 3. diffBisect : changed conditional boundary → NO_COVERAGE 4. diffBisect : changed conditional boundary → NO_COVERAGE 5. diffBisect : negated conditional → NO_COVERAGE |
if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] != -1) { |
| 358 | // Mirror x2 onto top-left coordinate system. | |
| 359 |
1
1. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
int x2 = text1Length - v2[k2Offset]; |
| 360 |
2
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : changed conditional boundary → NO_COVERAGE |
if (x1 >= x2) { |
| 361 | // Overlap detected. | |
| 362 |
1
1. diffBisect : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffBisect → NO_COVERAGE |
return this.diffBisectSplit(text1, text2, x1, y1, deadline); |
| 363 | } | |
| 364 | } | |
| 365 | } | |
| 366 | } | |
| 367 | ||
| 368 | // Walk the reverse path one step. | |
| 369 |
5
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 2. diffBisect : removed negation → NO_COVERAGE 3. diffBisect : negated conditional → NO_COVERAGE 4. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE 5. diffBisect : changed conditional boundary → NO_COVERAGE |
for (int k2 = -d + k2start; k2 <= d - k2end; k2 += 2) { |
| 370 |
1
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE |
int k2Offset = maxD + k2; |
| 371 | int x2; | |
| 372 |
7
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 2. diffBisect : changed conditional boundary → NO_COVERAGE 3. diffBisect : removed negation → NO_COVERAGE 4. diffBisect : negated conditional → NO_COVERAGE 5. diffBisect : negated conditional → NO_COVERAGE 6. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE 7. diffBisect : negated conditional → NO_COVERAGE |
if (k2 == -d || (k2 != d && v2[k2Offset - 1] < v2[k2Offset + 1])) { |
| 373 |
1
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE |
x2 = v2[k2Offset + 1]; |
| 374 | } else { | |
| 375 |
2
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 2. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
x2 = v2[k2Offset - 1] + 1; |
| 376 | } | |
| 377 |
1
1. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
int y2 = x2 - k2; |
| 378 |
6
1. diffBisect : changed conditional boundary → NO_COVERAGE 2. diffBisect : negated conditional → NO_COVERAGE 3. diffBisect : negated conditional → NO_COVERAGE 4. diffBisect : changed conditional boundary → NO_COVERAGE 5. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE 6. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
while (x2 < text1Length && y2 < text2Length |
| 379 |
2
1. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE 2. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
&& text1.charAt(text1Length - x2 - 1) |
| 380 |
1
1. diffBisect : negated conditional → NO_COVERAGE |
== text2.charAt(text2Length - y2 - 1)) { |
| 381 |
1
1. diffBisect : Changed increment from 1 to -1 → NO_COVERAGE |
x2++; |
| 382 |
1
1. diffBisect : Changed increment from 1 to -1 → NO_COVERAGE |
y2++; |
| 383 | } | |
| 384 | v2[k2Offset] = x2; | |
| 385 |
2
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : changed conditional boundary → NO_COVERAGE |
if (x2 > text1Length) { |
| 386 | // Ran off the left of the graph. | |
| 387 |
1
1. diffBisect : Changed increment from 2 to -2 → NO_COVERAGE |
k2end += 2; |
| 388 |
2
1. diffBisect : changed conditional boundary → NO_COVERAGE 2. diffBisect : negated conditional → NO_COVERAGE |
} else if (y2 > text2Length) { |
| 389 | // Ran off the top of the graph. | |
| 390 |
1
1. diffBisect : Changed increment from 2 to -2 → NO_COVERAGE |
k2start += 2; |
| 391 |
1
1. diffBisect : negated conditional → NO_COVERAGE |
} else if (!front) { |
| 392 |
2
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 2. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
int k1Offset = maxD + delta - k2; |
| 393 |
5
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : negated conditional → NO_COVERAGE 3. diffBisect : changed conditional boundary → NO_COVERAGE 4. diffBisect : changed conditional boundary → NO_COVERAGE 5. diffBisect : negated conditional → NO_COVERAGE |
if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] != -1) { |
| 394 | int x1 = v1[k1Offset]; | |
| 395 |
2
1. diffBisect : Replaced integer addition with subtraction → NO_COVERAGE 2. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
int y1 = maxD + x1 - k1Offset; |
| 396 | // Mirror x2 onto top-left coordinate system. | |
| 397 |
1
1. diffBisect : Replaced integer subtraction with addition → NO_COVERAGE |
x2 = text1Length - x2; |
| 398 |
2
1. diffBisect : negated conditional → NO_COVERAGE 2. diffBisect : changed conditional boundary → NO_COVERAGE |
if (x1 >= x2) { |
| 399 | // Overlap detected. | |
| 400 |
1
1. diffBisect : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffBisect → NO_COVERAGE |
return this.diffBisectSplit(text1, text2, x1, y1, deadline); |
| 401 | } | |
| 402 | } | |
| 403 | } | |
| 404 | } | |
| 405 | } | |
| 406 | // Diff took too long and hit the deadline or | |
| 407 | // number of diffs equals number of characters, no commonality at all. | |
| 408 | LinkedList<Diff> diffs = new LinkedList<>(); | |
| 409 | diffs.add(new Diff(Operation.DELETE, text1)); | |
| 410 | diffs.add(new Diff(Operation.INSERT, text2)); | |
| 411 |
1
1. diffBisect : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffBisect → NO_COVERAGE |
return diffs; |
| 412 | } | |
| 413 | ||
| 414 | /** | |
| 415 | * Given the location of the 'middle snake', split the diff in two parts | |
| 416 | * and recurse. | |
| 417 | * @param text1 Old string to be diffed. | |
| 418 | * @param text2 New string to be diffed. | |
| 419 | * @param x Index of split point in text1. | |
| 420 | * @param y Index of split point in text2. | |
| 421 | * @param deadline Time at which to bail if not yet complete. | |
| 422 | * @return LinkedList of Diff objects. | |
| 423 | */ | |
| 424 | private LinkedList<Diff> diffBisectSplit(String text1, String text2, int x, int y, long deadline) { | |
| 425 | String text1a = text1.substring(0, x); | |
| 426 | String text2a = text2.substring(0, y); | |
| 427 | String text1b = text1.substring(x); | |
| 428 | String text2b = text2.substring(y); | |
| 429 | ||
| 430 | // Compute both diffs serially. | |
| 431 | LinkedList<Diff> diffs = this.diffMain(text1a, text2a, false, deadline); | |
| 432 | List<Diff> diffsb = this.diffMain(text1b, text2b, false, deadline); | |
| 433 | ||
| 434 | diffs.addAll(diffsb); | |
| 435 |
1
1. diffBisectSplit : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffBisectSplit → NO_COVERAGE |
return diffs; |
| 436 | } | |
| 437 | ||
| 438 | /** | |
| 439 | * Split two texts into a list of strings. Reduce the texts to a string of | |
| 440 | * hashes where each Unicode character represents one line. | |
| 441 | * @param text1 First string. | |
| 442 | * @param text2 Second string. | |
| 443 | * @return An object containing the encoded text1, the encoded text2 and | |
| 444 | * the List of unique strings. The zeroth element of the List of | |
| 445 | * unique strings is intentionally blank. | |
| 446 | */ | |
| 447 | protected LinesToCharsResult diffLinesToChars(String text1, String text2) { | |
| 448 | List<String> lineArray = new ArrayList<>(); | |
| 449 | Map<String, Integer> lineHash = new HashMap<>(); | |
| 450 | // e.g. linearray[4] == "Hello\n" | |
| 451 | // e.g. linehash.get("Hello\n") == 4 | |
| 452 | ||
| 453 | // "\x00" is a valid character, but various debuggers don't like it. | |
| 454 | // So we'll insert a junk entry to avoid generating a null character. | |
| 455 | lineArray.add(StringUtils.EMPTY); | |
| 456 | ||
| 457 | String chars1 = this.diffLinesToCharsMunge(text1, lineArray, lineHash); | |
| 458 | String chars2 = this.diffLinesToCharsMunge(text2, lineArray, lineHash); | |
| 459 |
1
1. diffLinesToChars : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffLinesToChars → NO_COVERAGE |
return new LinesToCharsResult(chars1, chars2, lineArray); |
| 460 | } | |
| 461 | ||
| 462 | /** | |
| 463 | * Split a text into a list of strings. Reduce the texts to a string of | |
| 464 | * hashes where each Unicode character represents one line. | |
| 465 | * @param text String to encode. | |
| 466 | * @param lineArray List of unique strings. | |
| 467 | * @param lineHash Map of strings to indices. | |
| 468 | * @return Encoded string. | |
| 469 | */ | |
| 470 | private String diffLinesToCharsMunge(String text, List<String> lineArray, | |
| 471 | Map<String, Integer> lineHash) { | |
| 472 | int lineStart = 0; | |
| 473 | int lineEnd = -1; | |
| 474 | String line; | |
| 475 | StringBuilder chars = new StringBuilder(); | |
| 476 | // Walk the text, pulling out a substring for each line. | |
| 477 | // text.split('\n') would would temporarily double our memory footprint. | |
| 478 | // Modifying text would create many large strings to garbage collect. | |
| 479 |
3
1. diffLinesToCharsMunge : Replaced integer subtraction with addition → NO_COVERAGE 2. diffLinesToCharsMunge : negated conditional → NO_COVERAGE 3. diffLinesToCharsMunge : changed conditional boundary → NO_COVERAGE |
while (lineEnd < text.length() - 1) { |
| 480 | lineEnd = text.indexOf('\n', lineStart); | |
| 481 |
1
1. diffLinesToCharsMunge : negated conditional → NO_COVERAGE |
if (lineEnd == -1) { |
| 482 |
1
1. diffLinesToCharsMunge : Replaced integer subtraction with addition → NO_COVERAGE |
lineEnd = text.length() - 1; |
| 483 | } | |
| 484 |
1
1. diffLinesToCharsMunge : Replaced integer addition with subtraction → NO_COVERAGE |
line = text.substring(lineStart, lineEnd + 1); |
| 485 |
1
1. diffLinesToCharsMunge : Replaced integer addition with subtraction → NO_COVERAGE |
lineStart = lineEnd + 1; |
| 486 | ||
| 487 |
1
1. diffLinesToCharsMunge : negated conditional → NO_COVERAGE |
if (lineHash.containsKey(line)) { |
| 488 | chars.append((char) (int) lineHash.get(line)); | |
| 489 | } else { | |
| 490 | lineArray.add(line); | |
| 491 |
1
1. diffLinesToCharsMunge : Replaced integer subtraction with addition → NO_COVERAGE |
lineHash.put(line, lineArray.size() - 1); |
| 492 |
1
1. diffLinesToCharsMunge : Replaced integer subtraction with addition → NO_COVERAGE |
chars.append((char) (lineArray.size() - 1)); |
| 493 | } | |
| 494 | } | |
| 495 |
1
1. diffLinesToCharsMunge : replaced return value with "" for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffLinesToCharsMunge → NO_COVERAGE |
return chars.toString(); |
| 496 | } | |
| 497 | ||
| 498 | /** | |
| 499 | * Rehydrate the text in a diff from a string of line hashes to real lines of | |
| 500 | * text. | |
| 501 | * @param diffs LinkedList of Diff objects. | |
| 502 | * @param lineArray List of unique strings. | |
| 503 | */ | |
| 504 | protected void diffCharsToLines(List<Diff> diffs, List<String> lineArray) { | |
| 505 | StringBuilder text; | |
| 506 | for (Diff diff : diffs) { | |
| 507 | text = new StringBuilder(); | |
| 508 |
2
1. diffCharsToLines : changed conditional boundary → NO_COVERAGE 2. diffCharsToLines : negated conditional → NO_COVERAGE |
for (int y = 0; y < diff.getText().length(); y++) { |
| 509 | text.append(lineArray.get(diff.getText().charAt(y))); | |
| 510 | } | |
| 511 |
1
1. diffCharsToLines : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
diff.setText(text.toString()); |
| 512 | } | |
| 513 | } | |
| 514 | ||
| 515 | /** | |
| 516 | * Determine the common prefix of two strings | |
| 517 | * @param text1 First string. | |
| 518 | * @param text2 Second string. | |
| 519 | * @return The number of characters common to the start of each string. | |
| 520 | */ | |
| 521 | public int diffCommonPrefix(String text1, String text2) { | |
| 522 | // Performance analysis: http://neil.fraser.name/news/2007/10/09/ | |
| 523 | int n = Math.min(text1.length(), text2.length()); | |
| 524 |
2
1. diffCommonPrefix : changed conditional boundary → NO_COVERAGE 2. diffCommonPrefix : negated conditional → NO_COVERAGE |
for (int i = 0; i < n; i++) { |
| 525 |
1
1. diffCommonPrefix : negated conditional → NO_COVERAGE |
if (text1.charAt(i) != text2.charAt(i)) { |
| 526 |
1
1. diffCommonPrefix : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCommonPrefix → NO_COVERAGE |
return i; |
| 527 | } | |
| 528 | } | |
| 529 |
1
1. diffCommonPrefix : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCommonPrefix → NO_COVERAGE |
return n; |
| 530 | } | |
| 531 | ||
| 532 | /** | |
| 533 | * Determine the common suffix of two strings | |
| 534 | * @param text1 First string. | |
| 535 | * @param text2 Second string. | |
| 536 | * @return The number of characters common to the end of each string. | |
| 537 | */ | |
| 538 | public int diffCommonSuffix(String text1, String text2) { | |
| 539 | // Performance analysis: http://neil.fraser.name/news/2007/10/09/ | |
| 540 | int text1Length = text1.length(); | |
| 541 | int text2Length = text2.length(); | |
| 542 | int n = Math.min(text1Length, text2Length); | |
| 543 |
2
1. diffCommonSuffix : changed conditional boundary → NO_COVERAGE 2. diffCommonSuffix : negated conditional → NO_COVERAGE |
for (int i = 1; i <= n; i++) { |
| 544 |
3
1. diffCommonSuffix : negated conditional → NO_COVERAGE 2. diffCommonSuffix : Replaced integer subtraction with addition → NO_COVERAGE 3. diffCommonSuffix : Replaced integer subtraction with addition → NO_COVERAGE |
if (text1.charAt(text1Length - i) != text2.charAt(text2Length - i)) { |
| 545 |
2
1. diffCommonSuffix : Replaced integer subtraction with addition → NO_COVERAGE 2. diffCommonSuffix : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCommonSuffix → NO_COVERAGE |
return i - 1; |
| 546 | } | |
| 547 | } | |
| 548 |
1
1. diffCommonSuffix : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCommonSuffix → NO_COVERAGE |
return n; |
| 549 | } | |
| 550 | ||
| 551 | /** | |
| 552 | * Determine if the suffix of one string is the prefix of another. | |
| 553 | * @param valueText1 First string. | |
| 554 | * @param valueText2 Second string. | |
| 555 | * @return The number of characters common to the end of the first | |
| 556 | * string and the start of the second string. | |
| 557 | */ | |
| 558 | protected int diffCommonOverlap(String valueText1, String valueText2) { | |
| 559 | String text1 = valueText1; | |
| 560 | String text2 = valueText2; | |
| 561 | ||
| 562 | // Cache the text lengths to prevent multiple calls. | |
| 563 | int text1Length = text1.length(); | |
| 564 | int text2Length = text2.length(); | |
| 565 | // Eliminate the null case. | |
| 566 |
2
1. diffCommonOverlap : negated conditional → NO_COVERAGE 2. diffCommonOverlap : negated conditional → NO_COVERAGE |
if (text1Length == 0 || text2Length == 0) { |
| 567 | return 0; | |
| 568 | } | |
| 569 | // Truncate the longer string. | |
| 570 |
2
1. diffCommonOverlap : negated conditional → NO_COVERAGE 2. diffCommonOverlap : changed conditional boundary → NO_COVERAGE |
if (text1Length > text2Length) { |
| 571 |
1
1. diffCommonOverlap : Replaced integer subtraction with addition → NO_COVERAGE |
text1 = text1.substring(text1Length - text2Length); |
| 572 |
2
1. diffCommonOverlap : changed conditional boundary → NO_COVERAGE 2. diffCommonOverlap : negated conditional → NO_COVERAGE |
} else if (text1Length < text2Length) { |
| 573 | text2 = text2.substring(0, text1Length); | |
| 574 | } | |
| 575 | int textLength = Math.min(text1Length, text2Length); | |
| 576 | // Quick check for the worst case. | |
| 577 |
1
1. diffCommonOverlap : negated conditional → NO_COVERAGE |
if (text1.equals(text2)) { |
| 578 |
1
1. diffCommonOverlap : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCommonOverlap → NO_COVERAGE |
return textLength; |
| 579 | } | |
| 580 | ||
| 581 | // Start by looking for a single character match | |
| 582 | // and increase length until no match is found. | |
| 583 | // Performance analysis: http://neil.fraser.name/news/2010/11/04/ | |
| 584 | int best = 0; | |
| 585 | int length = 1; | |
| 586 | while (true) { | |
| 587 |
1
1. diffCommonOverlap : Replaced integer subtraction with addition → NO_COVERAGE |
String pattern = text1.substring(textLength - length); |
| 588 | int found = text2.indexOf(pattern); | |
| 589 |
1
1. diffCommonOverlap : negated conditional → NO_COVERAGE |
if (found == -1) { |
| 590 |
1
1. diffCommonOverlap : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCommonOverlap → NO_COVERAGE |
return best; |
| 591 | } | |
| 592 |
1
1. diffCommonOverlap : Replaced integer addition with subtraction → NO_COVERAGE |
length += found; |
| 593 |
3
1. diffCommonOverlap : negated conditional → NO_COVERAGE 2. diffCommonOverlap : Replaced integer subtraction with addition → NO_COVERAGE 3. diffCommonOverlap : negated conditional → NO_COVERAGE |
if (found == 0 || text1.substring(textLength - length).equals( |
| 594 | text2.substring(0, length))) { | |
| 595 | best = length; | |
| 596 |
1
1. diffCommonOverlap : Changed increment from 1 to -1 → NO_COVERAGE |
length++; |
| 597 | } | |
| 598 | } | |
| 599 | } | |
| 600 | ||
| 601 | /** | |
| 602 | * Do the two texts share a substring which is at least half the length of | |
| 603 | * the longer text? | |
| 604 | * This speedup can produce non-minimal diffs. | |
| 605 | * @param text1 First string. | |
| 606 | * @param text2 Second string. | |
| 607 | * @return Five element String array, containing the prefix of text1, the | |
| 608 | * suffix of text1, the prefix of text2, the suffix of text2 and the | |
| 609 | * common middle. Or null if there was no match. | |
| 610 | */ | |
| 611 | protected String[] diffHalfMatch(String text1, String text2) { | |
| 612 |
2
1. diffHalfMatch : changed conditional boundary → NO_COVERAGE 2. diffHalfMatch : negated conditional → NO_COVERAGE |
String longtext = text1.length() > text2.length() ? text1 : text2; |
| 613 |
2
1. diffHalfMatch : negated conditional → NO_COVERAGE 2. diffHalfMatch : changed conditional boundary → NO_COVERAGE |
String shorttext = text1.length() > text2.length() ? text2 : text1; |
| 614 |
5
1. diffHalfMatch : changed conditional boundary → NO_COVERAGE 2. diffHalfMatch : Replaced integer multiplication with division → NO_COVERAGE 3. diffHalfMatch : changed conditional boundary → NO_COVERAGE 4. diffHalfMatch : negated conditional → NO_COVERAGE 5. diffHalfMatch : negated conditional → NO_COVERAGE |
if (longtext.length() < 4 || shorttext.length() * 2 < longtext.length()) { |
| 615 | return null; // Pointless. | |
| 616 | } | |
| 617 | ||
| 618 | // First check if the second quarter is the seed for a half-match. | |
| 619 |
2
1. diffHalfMatch : Replaced integer addition with subtraction → NO_COVERAGE 2. diffHalfMatch : Replaced integer division with multiplication → NO_COVERAGE |
String[] hm1 = this.diffHalfMatchI(longtext, shorttext, (longtext.length() + 3) / 4); |
| 620 | // Check again based on the third quarter. | |
| 621 |
2
1. diffHalfMatch : Replaced integer addition with subtraction → NO_COVERAGE 2. diffHalfMatch : Replaced integer division with multiplication → NO_COVERAGE |
String[] hm2 = this.diffHalfMatchI(longtext, shorttext, (longtext.length() + 1) / 2); |
| 622 | String[] hm; | |
| 623 |
2
1. diffHalfMatch : negated conditional → NO_COVERAGE 2. diffHalfMatch : negated conditional → NO_COVERAGE |
if (hm1 == null && hm2 == null) { |
| 624 | return null; | |
| 625 |
1
1. diffHalfMatch : negated conditional → NO_COVERAGE |
} else if (hm2 == null) { |
| 626 | hm = hm1; | |
| 627 |
1
1. diffHalfMatch : negated conditional → NO_COVERAGE |
} else if (hm1 == null) { |
| 628 | hm = hm2; | |
| 629 | } else { | |
| 630 | // Both matched. Select the longest. | |
| 631 |
2
1. diffHalfMatch : negated conditional → NO_COVERAGE 2. diffHalfMatch : changed conditional boundary → NO_COVERAGE |
hm = hm1[4].length() > hm2[4].length() ? hm1 : hm2; |
| 632 | } | |
| 633 | ||
| 634 | // A half-match was found, sort out the return data. | |
| 635 |
2
1. diffHalfMatch : changed conditional boundary → NO_COVERAGE 2. diffHalfMatch : negated conditional → NO_COVERAGE |
if (text1.length() > text2.length()) { |
| 636 |
1
1. diffHalfMatch : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffHalfMatch → NO_COVERAGE |
return hm; |
| 637 | } else { | |
| 638 |
1
1. diffHalfMatch : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffHalfMatch → NO_COVERAGE |
return new String[]{hm[2], hm[3], hm[0], hm[1], hm[4]}; |
| 639 | } | |
| 640 | } | |
| 641 | ||
| 642 | /** | |
| 643 | * Does a substring of shorttext exist within longtext such that the | |
| 644 | * substring is at least half the length of longtext? | |
| 645 | * @param longtext Longer string. | |
| 646 | * @param shorttext Shorter string. | |
| 647 | * @param i Start index of quarter length substring within longtext. | |
| 648 | * @return Five element String array, containing the prefix of longtext, the | |
| 649 | * suffix of longtext, the prefix of shorttext, the suffix of shorttext | |
| 650 | * and the common middle. Or null if there was no match. | |
| 651 | */ | |
| 652 | private String[] diffHalfMatchI(String longtext, String shorttext, int i) { | |
| 653 | // Start with a 1/4 length substring at position i as a seed. | |
| 654 |
2
1. diffHalfMatchI : Replaced integer division with multiplication → NO_COVERAGE 2. diffHalfMatchI : Replaced integer addition with subtraction → NO_COVERAGE |
String seed = longtext.substring(i, i + longtext.length() / 4); |
| 655 | int j = -1; | |
| 656 | String bestCommon = StringUtils.EMPTY; | |
| 657 | String bestLongtextA = StringUtils.EMPTY; | |
| 658 | String bestLongtextB = StringUtils.EMPTY; | |
| 659 | String bestShorttextA = StringUtils.EMPTY; | |
| 660 | String bestShorttextB = StringUtils.EMPTY; | |
| 661 |
2
1. diffHalfMatchI : Replaced integer addition with subtraction → NO_COVERAGE 2. diffHalfMatchI : negated conditional → NO_COVERAGE |
while ((j = shorttext.indexOf(seed, j + 1)) != -1) { |
| 662 | int prefixLength = this.diffCommonPrefix(longtext.substring(i), | |
| 663 | shorttext.substring(j)); | |
| 664 | int suffixLength = this.diffCommonSuffix(longtext.substring(0, i), | |
| 665 | shorttext.substring(0, j)); | |
| 666 |
3
1. diffHalfMatchI : negated conditional → NO_COVERAGE 2. diffHalfMatchI : Replaced integer addition with subtraction → NO_COVERAGE 3. diffHalfMatchI : changed conditional boundary → NO_COVERAGE |
if (bestCommon.length() < suffixLength + prefixLength) { |
| 667 |
2
1. diffHalfMatchI : Replaced integer subtraction with addition → NO_COVERAGE 2. diffHalfMatchI : Replaced integer addition with subtraction → NO_COVERAGE |
bestCommon = shorttext.substring(j - suffixLength, j) |
| 668 | + shorttext.substring(j, j + prefixLength); | |
| 669 |
1
1. diffHalfMatchI : Replaced integer subtraction with addition → NO_COVERAGE |
bestLongtextA = longtext.substring(0, i - suffixLength); |
| 670 |
1
1. diffHalfMatchI : Replaced integer addition with subtraction → NO_COVERAGE |
bestLongtextB = longtext.substring(i + prefixLength); |
| 671 |
1
1. diffHalfMatchI : Replaced integer subtraction with addition → NO_COVERAGE |
bestShorttextA = shorttext.substring(0, j - suffixLength); |
| 672 |
1
1. diffHalfMatchI : Replaced integer addition with subtraction → NO_COVERAGE |
bestShorttextB = shorttext.substring(j + prefixLength); |
| 673 | } | |
| 674 | } | |
| 675 |
3
1. diffHalfMatchI : negated conditional → NO_COVERAGE 2. diffHalfMatchI : changed conditional boundary → NO_COVERAGE 3. diffHalfMatchI : Replaced integer multiplication with division → NO_COVERAGE |
if (bestCommon.length() * 2 >= longtext.length()) { |
| 676 |
1
1. diffHalfMatchI : replaced return value with null for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffHalfMatchI → NO_COVERAGE |
return new String[]{bestLongtextA, bestLongtextB, |
| 677 | bestShorttextA, bestShorttextB, bestCommon}; | |
| 678 | } else { | |
| 679 | return null; | |
| 680 | } | |
| 681 | } | |
| 682 | ||
| 683 | /** | |
| 684 | * Reduce the number of edits by eliminating semantically trivial equalities. | |
| 685 | * @param diffs LinkedList of Diff objects. | |
| 686 | */ | |
| 687 | public void diffCleanupSemantic(LinkedList<Diff> diffs) { | |
| 688 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (diffs.isEmpty()) { |
| 689 | return; | |
| 690 | } | |
| 691 | boolean changes = false; | |
| 692 | // Synchronized Stack to avoid Exception | |
| 693 | Stack<Diff> equalities = new Stack<>(); // Stack of qualities. | |
| 694 | String lastequality = null; // Always equal to equalities.lastElement().text | |
| 695 | ListIterator<Diff> pointer = diffs.listIterator(); | |
| 696 | // Number of characters that changed prior to the equality. | |
| 697 | int lengthInsertions1 = 0; | |
| 698 | int lengthDeletions1 = 0; | |
| 699 | // Number of characters that changed after the equality. | |
| 700 | int lengthInsertions2 = 0; | |
| 701 | int lengthDeletions2 = 0; | |
| 702 | Diff thisDiff = pointer.next(); | |
| 703 | ||
| 704 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
while (thisDiff != null) { |
| 705 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (thisDiff.getOperation() == Operation.EQUAL) { |
| 706 | // Equality found. | |
| 707 | equalities.push(thisDiff); | |
| 708 | lengthInsertions1 = lengthInsertions2; | |
| 709 | lengthDeletions1 = lengthDeletions2; | |
| 710 | lengthInsertions2 = 0; | |
| 711 | lengthDeletions2 = 0; | |
| 712 | lastequality = thisDiff.getText(); | |
| 713 | } else { | |
| 714 | // An insertion or deletion. | |
| 715 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (thisDiff.getOperation() == Operation.INSERT) { |
| 716 |
1
1. diffCleanupSemantic : Replaced integer addition with subtraction → NO_COVERAGE |
lengthInsertions2 += thisDiff.getText().length(); |
| 717 | } else { | |
| 718 |
1
1. diffCleanupSemantic : Replaced integer addition with subtraction → NO_COVERAGE |
lengthDeletions2 += thisDiff.getText().length(); |
| 719 | } | |
| 720 | // Eliminate an equality that is smaller or equal to the edits on both | |
| 721 | // sides of it. | |
| 722 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if ( |
| 723 | lastequality != null | |
| 724 |
2
1. diffCleanupSemantic : negated conditional → NO_COVERAGE 2. diffCleanupSemantic : changed conditional boundary → NO_COVERAGE |
&& lastequality.length() <= Math.max(lengthInsertions1, lengthDeletions1) |
| 725 |
2
1. diffCleanupSemantic : changed conditional boundary → NO_COVERAGE 2. diffCleanupSemantic : negated conditional → NO_COVERAGE |
&& lastequality.length() <= Math.max(lengthInsertions2, lengthDeletions2) |
| 726 | ) { | |
| 727 | // Walk back to offending equality. | |
| 728 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
while (thisDiff != equalities.lastElement()) { |
| 729 | thisDiff = pointer.previous(); | |
| 730 | } | |
| 731 | pointer.next(); | |
| 732 | ||
| 733 | // Replace equality with a delete. | |
| 734 |
1
1. diffCleanupSemantic : removed call to java/util/ListIterator::set → NO_COVERAGE |
pointer.set(new Diff(Operation.DELETE, lastequality)); |
| 735 | // Insert a corresponding an insert. | |
| 736 |
1
1. diffCleanupSemantic : removed call to java/util/ListIterator::add → NO_COVERAGE |
pointer.add(new Diff(Operation.INSERT, lastequality)); |
| 737 | ||
| 738 | equalities.pop(); // Throw away the equality we just deleted. | |
| 739 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (!equalities.empty()) { |
| 740 | // Throw away the previous equality (it needs to be reevaluated). | |
| 741 | equalities.pop(); | |
| 742 | } | |
| 743 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (equalities.empty()) { |
| 744 | // There are no previous equalities, walk back to the start. | |
| 745 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
while (pointer.hasPrevious()) { |
| 746 | pointer.previous(); | |
| 747 | } | |
| 748 | } else { | |
| 749 | // There is a safe equality we can fall back to. | |
| 750 | thisDiff = equalities.lastElement(); | |
| 751 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
while (thisDiff != pointer.previous()) { |
| 752 | // Intentionally empty loop. | |
| 753 | } | |
| 754 | } | |
| 755 | ||
| 756 | lengthInsertions1 = 0; // Reset the counters. | |
| 757 | lengthInsertions2 = 0; | |
| 758 | lengthDeletions1 = 0; | |
| 759 | lengthDeletions2 = 0; | |
| 760 | lastequality = null; | |
| 761 | changes = true; | |
| 762 | } | |
| 763 | } | |
| 764 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
thisDiff = pointer.hasNext() ? pointer.next() : null; |
| 765 | } | |
| 766 | ||
| 767 | // Normalize the diff. | |
| 768 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (changes) { |
| 769 |
1
1. diffCleanupSemantic : removed call to com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupMerge → NO_COVERAGE |
this.diffCleanupMerge(diffs); |
| 770 | } | |
| 771 |
1
1. diffCleanupSemantic : removed call to com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupSemanticLossless → NO_COVERAGE |
this.diffCleanupSemanticLossless(diffs); |
| 772 | ||
| 773 | // Find any overlaps between deletions and insertions. | |
| 774 | // e.g: <del>abcxxx</del><ins>xxxdef</ins> | |
| 775 | // -> <del>abc</del>xxx<ins>def</ins> | |
| 776 | // e.g: <del>xxxabc</del><ins>defxxx</ins> | |
| 777 | // -> <ins>def</ins>xxx<del>abc</del> | |
| 778 | // Only extract an overlap if it is as big as the edit ahead or behind it. | |
| 779 | pointer = diffs.listIterator(); | |
| 780 | Diff prevDiff = null; | |
| 781 | thisDiff = null; | |
| 782 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (pointer.hasNext()) { |
| 783 | prevDiff = pointer.next(); | |
| 784 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (pointer.hasNext()) { |
| 785 | thisDiff = pointer.next(); | |
| 786 | } | |
| 787 | } | |
| 788 | ||
| 789 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
while (thisDiff != null) { |
| 790 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (prevDiff.getOperation() == Operation.DELETE && |
| 791 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
thisDiff.getOperation() == Operation.INSERT) { |
| 792 | String deletion = prevDiff.getText(); | |
| 793 | String insertion = thisDiff.getText(); | |
| 794 | int overlapLength1 = this.diffCommonOverlap(deletion, insertion); | |
| 795 | int overlapLength2 = this.diffCommonOverlap(insertion, deletion); | |
| 796 |
2
1. diffCleanupSemantic : negated conditional → NO_COVERAGE 2. diffCleanupSemantic : changed conditional boundary → NO_COVERAGE |
if (overlapLength1 >= overlapLength2) { |
| 797 |
3
1. diffCleanupSemantic : changed conditional boundary → NO_COVERAGE 2. diffCleanupSemantic : Replaced double division with multiplication → NO_COVERAGE 3. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (overlapLength1 >= deletion.length() / 2.0 || |
| 798 |
3
1. diffCleanupSemantic : changed conditional boundary → NO_COVERAGE 2. diffCleanupSemantic : Replaced double division with multiplication → NO_COVERAGE 3. diffCleanupSemantic : negated conditional → NO_COVERAGE |
overlapLength1 >= insertion.length() / 2.0) { |
| 799 | // Overlap found. Insert an equality and trim the surrounding edits. | |
| 800 | pointer.previous(); | |
| 801 |
1
1. diffCleanupSemantic : removed call to java/util/ListIterator::add → NO_COVERAGE |
pointer.add(new Diff(Operation.EQUAL, |
| 802 | insertion.substring(0, overlapLength1))); | |
| 803 |
2
1. diffCleanupSemantic : Replaced integer subtraction with addition → NO_COVERAGE 2. diffCleanupSemantic : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
prevDiff.setText(deletion.substring(0, deletion.length() - overlapLength1)); |
| 804 |
1
1. diffCleanupSemantic : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
thisDiff.setText(insertion.substring(overlapLength1)); |
| 805 | // pointer.add inserts the element before the cursor, so there is | |
| 806 | // no need to step past the new element. | |
| 807 | } | |
| 808 | } else { | |
| 809 |
3
1. diffCleanupSemantic : changed conditional boundary → NO_COVERAGE 2. diffCleanupSemantic : Replaced double division with multiplication → NO_COVERAGE 3. diffCleanupSemantic : negated conditional → NO_COVERAGE |
if (overlapLength2 >= deletion.length() / 2.0 || |
| 810 |
3
1. diffCleanupSemantic : Replaced double division with multiplication → NO_COVERAGE 2. diffCleanupSemantic : negated conditional → NO_COVERAGE 3. diffCleanupSemantic : changed conditional boundary → NO_COVERAGE |
overlapLength2 >= insertion.length() / 2.0) { |
| 811 | // Reverse overlap found. | |
| 812 | // Insert an equality and swap and trim the surrounding edits. | |
| 813 | pointer.previous(); | |
| 814 |
1
1. diffCleanupSemantic : removed call to java/util/ListIterator::add → NO_COVERAGE |
pointer.add(new Diff(Operation.EQUAL, |
| 815 | deletion.substring(0, overlapLength2))); | |
| 816 |
1
1. diffCleanupSemantic : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setOperation → NO_COVERAGE |
prevDiff.setOperation(Operation.INSERT); |
| 817 |
2
1. diffCleanupSemantic : Replaced integer subtraction with addition → NO_COVERAGE 2. diffCleanupSemantic : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
prevDiff.setText(insertion.substring(0, insertion.length() - overlapLength2)); |
| 818 |
1
1. diffCleanupSemantic : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setOperation → NO_COVERAGE |
thisDiff.setOperation(Operation.DELETE); |
| 819 |
1
1. diffCleanupSemantic : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
thisDiff.setText(deletion.substring(overlapLength2)); |
| 820 | // pointer.add inserts the element before the cursor, so there is | |
| 821 | // no need to step past the new element. | |
| 822 | } | |
| 823 | } | |
| 824 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
thisDiff = pointer.hasNext() ? pointer.next() : null; |
| 825 | } | |
| 826 | prevDiff = thisDiff; | |
| 827 |
1
1. diffCleanupSemantic : negated conditional → NO_COVERAGE |
thisDiff = pointer.hasNext() ? pointer.next() : null; |
| 828 | } | |
| 829 | } | |
| 830 | ||
| 831 | /** | |
| 832 | * Look for single edits surrounded on both sides by equalities | |
| 833 | * which can be shifted sideways to align the edit to a word boundary. | |
| 834 | * e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came. | |
| 835 | * @param diffs LinkedList of Diff objects. | |
| 836 | */ | |
| 837 | public void diffCleanupSemanticLossless(List<Diff> diffs) { | |
| 838 | StringBuilder equality1 = new StringBuilder(); | |
| 839 | String edit; | |
| 840 | StringBuilder equality2 = new StringBuilder(); | |
| 841 | String commonString; | |
| 842 | int commonOffset; | |
| 843 | int score; | |
| 844 | int bestScore; | |
| 845 | String bestEquality1; | |
| 846 | String bestEdit; | |
| 847 | String bestEquality2; | |
| 848 | // Create a new iterator at the start. | |
| 849 | ListIterator<Diff> pointer = diffs.listIterator(); | |
| 850 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
Diff prevDiff = pointer.hasNext() ? pointer.next() : null; |
| 851 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
Diff thisDiff = pointer.hasNext() ? pointer.next() : null; |
| 852 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
Diff nextDiff = pointer.hasNext() ? pointer.next() : null; |
| 853 | ||
| 854 | // Intentionally ignore the first and last element (don't need checking). | |
| 855 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
while (nextDiff != null) { |
| 856 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
if (prevDiff.getOperation() == Operation.EQUAL && |
| 857 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
nextDiff.getOperation() == Operation.EQUAL) { |
| 858 | // This is a single edit surrounded by equalities. | |
| 859 |
1
1. diffCleanupSemanticLossless : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
equality1.setLength(0); |
| 860 | equality1.append(prevDiff.getText()); | |
| 861 | edit = thisDiff.getText(); | |
| 862 |
1
1. diffCleanupSemanticLossless : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
equality2.setLength(0); |
| 863 | equality2.append(nextDiff.getText()); | |
| 864 | ||
| 865 | // First, shift the edit as far left as possible. | |
| 866 | commonOffset = this.diffCommonSuffix(equality1.toString(), edit); | |
| 867 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
if (commonOffset != 0) { |
| 868 |
1
1. diffCleanupSemanticLossless : Replaced integer subtraction with addition → NO_COVERAGE |
commonString = edit.substring(edit.length() - commonOffset); |
| 869 |
1
1. diffCleanupSemanticLossless : Replaced integer subtraction with addition → NO_COVERAGE |
String substring = equality1.substring(0, equality1.length() - commonOffset); |
| 870 |
1
1. diffCleanupSemanticLossless : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
equality1.setLength(0); |
| 871 | equality1.append(substring); | |
| 872 |
1
1. diffCleanupSemanticLossless : Replaced integer subtraction with addition → NO_COVERAGE |
edit = commonString + edit.substring(0, edit.length() - commonOffset); |
| 873 | equality2.insert(0, commonString); | |
| 874 | } | |
| 875 | ||
| 876 | // Second, step character by character right, looking for the best fit. | |
| 877 | bestEquality1 = equality1.toString(); | |
| 878 | bestEdit = edit; | |
| 879 | bestEquality2 = equality2.toString(); | |
| 880 | bestScore = this.diffCleanupSemanticScore(equality1.toString(), edit) | |
| 881 |
1
1. diffCleanupSemanticLossless : Replaced integer addition with subtraction → NO_COVERAGE |
+ this.diffCleanupSemanticScore(edit, equality2.toString()); |
| 882 |
2
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE 2. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
while (!edit.isEmpty() && !equality2.isEmpty() |
| 883 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
&& edit.charAt(0) == equality2.charAt(0)) { |
| 884 | equality1.append(edit.charAt(0)); | |
| 885 | edit = edit.substring(1) + equality2.charAt(0); | |
| 886 | String substring = equality2.substring(1); | |
| 887 |
1
1. diffCleanupSemanticLossless : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
equality2.setLength(0); |
| 888 | equality2.append(substring); | |
| 889 | score = this.diffCleanupSemanticScore(equality1.toString(), edit) | |
| 890 |
1
1. diffCleanupSemanticLossless : Replaced integer addition with subtraction → NO_COVERAGE |
+ this.diffCleanupSemanticScore(edit, equality2.toString()); |
| 891 | // The >= encourages trailing rather than leading whitespace on edits. | |
| 892 |
2
1. diffCleanupSemanticLossless : changed conditional boundary → NO_COVERAGE 2. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
if (score >= bestScore) { |
| 893 | bestScore = score; | |
| 894 | bestEquality1 = equality1.toString(); | |
| 895 | bestEdit = edit; | |
| 896 | bestEquality2 = equality2.toString(); | |
| 897 | } | |
| 898 | } | |
| 899 | ||
| 900 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
if (!prevDiff.getText().equals(bestEquality1)) { |
| 901 | // We have an improvement, save it back to the diff. | |
| 902 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
if (!bestEquality1.isEmpty()) { |
| 903 |
1
1. diffCleanupSemanticLossless : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
prevDiff.setText(bestEquality1); |
| 904 | } else { | |
| 905 | pointer.previous(); // Walk past nextDiff. | |
| 906 | pointer.previous(); // Walk past thisDiff. | |
| 907 | pointer.previous(); // Walk past prevDiff. | |
| 908 |
1
1. diffCleanupSemanticLossless : removed call to java/util/ListIterator::remove → NO_COVERAGE |
pointer.remove(); // Delete prevDiff. |
| 909 | pointer.next(); // Walk past thisDiff. | |
| 910 | pointer.next(); // Walk past nextDiff. | |
| 911 | } | |
| 912 |
1
1. diffCleanupSemanticLossless : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
thisDiff.setText(bestEdit); |
| 913 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
if (!bestEquality2.isEmpty()) { |
| 914 |
1
1. diffCleanupSemanticLossless : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
nextDiff.setText(bestEquality2); |
| 915 | } else { | |
| 916 |
1
1. diffCleanupSemanticLossless : removed call to java/util/ListIterator::remove → NO_COVERAGE |
pointer.remove(); // Delete nextDiff. |
| 917 | nextDiff = thisDiff; | |
| 918 | thisDiff = prevDiff; | |
| 919 | } | |
| 920 | } | |
| 921 | } | |
| 922 | prevDiff = thisDiff; | |
| 923 | thisDiff = nextDiff; | |
| 924 |
1
1. diffCleanupSemanticLossless : negated conditional → NO_COVERAGE |
nextDiff = pointer.hasNext() ? pointer.next() : null; |
| 925 | } | |
| 926 | } | |
| 927 | ||
| 928 | /** | |
| 929 | * Given two strings, compute a score representing whether the internal | |
| 930 | * boundary falls on logical boundaries. | |
| 931 | * Scores range from 6 (best) to 0 (worst). | |
| 932 | * @param one First string. | |
| 933 | * @param two Second string. | |
| 934 | * @return The score. | |
| 935 | */ | |
| 936 | private int diffCleanupSemanticScore(String one, String two) { | |
| 937 |
2
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
if (one.isEmpty() || two.isEmpty()) { |
| 938 | // Edges are the best. | |
| 939 |
1
1. diffCleanupSemanticScore : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupSemanticScore → NO_COVERAGE |
return 6; |
| 940 | } | |
| 941 | ||
| 942 | // Each port of this function behaves slightly differently due to | |
| 943 | // subtle differences in each language's definition of things like | |
| 944 | // 'whitespace'. Since this function's purpose is largely cosmetic, | |
| 945 | // the choice has been made to use each language's native features | |
| 946 | // rather than force total conformity. | |
| 947 |
1
1. diffCleanupSemanticScore : Replaced integer subtraction with addition → NO_COVERAGE |
char char1 = one.charAt(one.length() - 1); |
| 948 | char char2 = two.charAt(0); | |
| 949 |
1
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
boolean nonAlphaNumeric1 = !Character.isLetterOrDigit(char1); |
| 950 |
1
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
boolean nonAlphaNumeric2 = !Character.isLetterOrDigit(char2); |
| 951 |
2
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
boolean whitespace1 = nonAlphaNumeric1 && Character.isWhitespace(char1); |
| 952 |
2
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
boolean whitespace2 = nonAlphaNumeric2 && Character.isWhitespace(char2); |
| 953 |
1
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
boolean lineBreak1 = whitespace1 |
| 954 |
1
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
&& Character.getType(char1) == Character.CONTROL; |
| 955 |
1
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
boolean lineBreak2 = whitespace2 |
| 956 |
1
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
&& Character.getType(char2) == Character.CONTROL; |
| 957 |
2
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
boolean blankLine1 = lineBreak1 && DiffMatchPatch.BLANK_LINE_END.matcher(one).find(); |
| 958 |
2
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
boolean blankLine2 = lineBreak2 && DiffMatchPatch.BLANK_LINE_START.matcher(two).find(); |
| 959 | ||
| 960 |
2
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
if (blankLine1 || blankLine2) { |
| 961 | // Five points for blank lines. | |
| 962 |
1
1. diffCleanupSemanticScore : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupSemanticScore → NO_COVERAGE |
return 5; |
| 963 |
2
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
} else if (lineBreak1 || lineBreak2) { |
| 964 | // Four points for line breaks. | |
| 965 |
1
1. diffCleanupSemanticScore : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupSemanticScore → NO_COVERAGE |
return 4; |
| 966 |
3
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 3. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
} else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) { |
| 967 | // Three points for end of sentences. | |
| 968 |
1
1. diffCleanupSemanticScore : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupSemanticScore → NO_COVERAGE |
return 3; |
| 969 |
2
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
} else if (whitespace1 || whitespace2) { |
| 970 | // Two points for whitespace. | |
| 971 |
1
1. diffCleanupSemanticScore : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupSemanticScore → NO_COVERAGE |
return 2; |
| 972 |
2
1. diffCleanupSemanticScore : negated conditional → NO_COVERAGE 2. diffCleanupSemanticScore : negated conditional → NO_COVERAGE |
} else if (nonAlphaNumeric1 || nonAlphaNumeric2) { |
| 973 | // One point for non-alphanumeric. | |
| 974 |
1
1. diffCleanupSemanticScore : replaced int return with 0 for com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupSemanticScore → NO_COVERAGE |
return 1; |
| 975 | } | |
| 976 | return 0; | |
| 977 | } | |
| 978 | ||
| 979 | /** | |
| 980 | * Reduce the number of edits by eliminating operationally trivial equalities. | |
| 981 | * @param diffs LinkedList of Diff objects. | |
| 982 | */ | |
| 983 | public void diffCleanupEfficiency(LinkedList<Diff> diffs) { | |
| 984 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
if (diffs.isEmpty()) { |
| 985 | return; | |
| 986 | } | |
| 987 | boolean changes = false; | |
| 988 | // Synchronized Stack to avoid Exception | |
| 989 | Stack<Diff> equalities = new Stack<>(); // Stack of equalities. | |
| 990 | String lastequality = null; // Always equal to equalities.lastElement().text | |
| 991 | ListIterator<Diff> pointer = diffs.listIterator(); | |
| 992 | // Is there an insertion operation before the last equality. | |
| 993 | boolean preIns = false; | |
| 994 | // Is there a deletion operation before the last equality. | |
| 995 | boolean preDel = false; | |
| 996 | // Is there an insertion operation after the last equality. | |
| 997 | boolean postIns = false; | |
| 998 | // Is there a deletion operation after the last equality. | |
| 999 | boolean postDel = false; | |
| 1000 | Diff thisDiff = pointer.next(); | |
| 1001 | Diff safeDiff = thisDiff; // The last Diff that is known to be unsplitable. | |
| 1002 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
while (thisDiff != null) { |
| 1003 | ||
| 1004 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
if (thisDiff.getOperation() == Operation.EQUAL) { |
| 1005 | ||
| 1006 | // Equality found. | |
| 1007 |
4
1. diffCleanupEfficiency : changed conditional boundary → NO_COVERAGE 2. diffCleanupEfficiency : negated conditional → NO_COVERAGE 3. diffCleanupEfficiency : negated conditional → NO_COVERAGE 4. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
if (thisDiff.getText().length() < DiffMatchPatch.DIFF_EDIT_COST && (postIns || postDel)) { |
| 1008 | // Candidate found. | |
| 1009 | equalities.push(thisDiff); | |
| 1010 | preIns = postIns; | |
| 1011 | preDel = postDel; | |
| 1012 | lastequality = thisDiff.getText(); | |
| 1013 | } else { | |
| 1014 | // Not a candidate, and can never become one. | |
| 1015 |
1
1. diffCleanupEfficiency : removed call to java/util/Stack::clear → NO_COVERAGE |
equalities.clear(); |
| 1016 | lastequality = null; | |
| 1017 | safeDiff = thisDiff; | |
| 1018 | } | |
| 1019 | postIns = postDel = false; | |
| 1020 | } else { | |
| 1021 | // An insertion or deletion. | |
| 1022 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
if (thisDiff.getOperation() == Operation.DELETE) { |
| 1023 | postDel = true; | |
| 1024 | } else { | |
| 1025 | postIns = true; | |
| 1026 | } | |
| 1027 | ||
| 1028 | /* | |
| 1029 | * Five types to be split: | |
| 1030 | * <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del> | |
| 1031 | * <ins>A</ins>X<ins>C</ins><del>D</del> | |
| 1032 | * <ins>A</ins><del>B</del>X<ins>C</ins> | |
| 1033 | * <ins>A</del>X<ins>C</ins><del>D</del> | |
| 1034 | * <ins>A</ins><del>B</del>X<del>C</del> | |
| 1035 | */ | |
| 1036 |
5
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE 2. diffCleanupEfficiency : negated conditional → NO_COVERAGE 3. diffCleanupEfficiency : negated conditional → NO_COVERAGE 4. diffCleanupEfficiency : negated conditional → NO_COVERAGE 5. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
if ( |
| 1037 | lastequality != null | |
| 1038 | && ( | |
| 1039 | (preIns && preDel && postIns && postDel) | |
| 1040 | || ( | |
| 1041 |
2
1. diffCleanupEfficiency : changed conditional boundary → NO_COVERAGE 2. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
(lastequality.length() < DiffMatchPatch.DIFF_EDIT_COST / 2) |
| 1042 |
8
1. diffCleanupEfficiency : Replaced integer addition with subtraction → NO_COVERAGE 2. diffCleanupEfficiency : negated conditional → NO_COVERAGE 3. diffCleanupEfficiency : negated conditional → NO_COVERAGE 4. diffCleanupEfficiency : negated conditional → NO_COVERAGE 5. diffCleanupEfficiency : negated conditional → NO_COVERAGE 6. diffCleanupEfficiency : Replaced integer addition with subtraction → NO_COVERAGE 7. diffCleanupEfficiency : Replaced integer addition with subtraction → NO_COVERAGE 8. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
&& ((preIns ? 1 : 0) + (preDel ? 1 : 0) + (postIns ? 1 : 0) + (postDel ? 1 : 0)) == 3 |
| 1043 | ) | |
| 1044 | ) | |
| 1045 | ) { | |
| 1046 | // Walk back to offending equality. | |
| 1047 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
while (thisDiff != equalities.lastElement()) { |
| 1048 | thisDiff = pointer.previous(); | |
| 1049 | } | |
| 1050 | pointer.next(); | |
| 1051 | ||
| 1052 | // Replace equality with a delete. | |
| 1053 |
1
1. diffCleanupEfficiency : removed call to java/util/ListIterator::set → NO_COVERAGE |
pointer.set(new Diff(Operation.DELETE, lastequality)); |
| 1054 | // Insert a corresponding an insert. | |
| 1055 | thisDiff = new Diff(Operation.INSERT, lastequality); | |
| 1056 |
1
1. diffCleanupEfficiency : removed call to java/util/ListIterator::add → NO_COVERAGE |
pointer.add(thisDiff); |
| 1057 | ||
| 1058 | equalities.pop(); // Throw away the equality we just deleted. | |
| 1059 | lastequality = null; | |
| 1060 |
2
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE 2. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
if (preIns && preDel) { |
| 1061 | // No changes made which could affect previous entry, keep going. | |
| 1062 | postIns = postDel = true; | |
| 1063 |
1
1. diffCleanupEfficiency : removed call to java/util/Stack::clear → NO_COVERAGE |
equalities.clear(); |
| 1064 | safeDiff = thisDiff; | |
| 1065 | } else { | |
| 1066 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
if (!equalities.empty()) { |
| 1067 | // Throw away the previous equality (it needs to be reevaluated). | |
| 1068 | equalities.pop(); | |
| 1069 | } | |
| 1070 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
if (equalities.empty()) { |
| 1071 | // There are no previous questionable equalities, | |
| 1072 | // walk back to the last known safe diff. | |
| 1073 | thisDiff = safeDiff; | |
| 1074 | } else { | |
| 1075 | // There is an equality we can fall back to. | |
| 1076 | thisDiff = equalities.lastElement(); | |
| 1077 | } | |
| 1078 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
while (thisDiff != pointer.previous()) { |
| 1079 | // Intentionally empty loop. | |
| 1080 | } | |
| 1081 | postIns = postDel = false; | |
| 1082 | } | |
| 1083 | ||
| 1084 | changes = true; | |
| 1085 | } | |
| 1086 | } | |
| 1087 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
thisDiff = pointer.hasNext() ? pointer.next() : null; |
| 1088 | } | |
| 1089 | ||
| 1090 |
1
1. diffCleanupEfficiency : negated conditional → NO_COVERAGE |
if (changes) { |
| 1091 |
1
1. diffCleanupEfficiency : removed call to com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupMerge → NO_COVERAGE |
this.diffCleanupMerge(diffs); |
| 1092 | } | |
| 1093 | } | |
| 1094 | ||
| 1095 | /** | |
| 1096 | * Reorder and merge like edit sections. Merge equalities. | |
| 1097 | * Any edit section can move as long as it doesn't cross an equality. | |
| 1098 | * @param diffs LinkedList of Diff objects. | |
| 1099 | */ | |
| 1100 | public void diffCleanupMerge(LinkedList<Diff> diffs) { | |
| 1101 | diffs.add(new Diff(Operation.EQUAL, StringUtils.EMPTY)); // Add a dummy entry at the end. | |
| 1102 | ListIterator<Diff> pointer = diffs.listIterator(); | |
| 1103 | int countDelete = 0; | |
| 1104 | int countInsert = 0; | |
| 1105 | StringBuilder textDelete = new StringBuilder(); | |
| 1106 | StringBuilder textInsert = new StringBuilder(); | |
| 1107 | Diff thisDiff = pointer.next(); | |
| 1108 | Diff prevEqual = null; | |
| 1109 | int commonlength; | |
| 1110 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
while (thisDiff != null) { |
| 1111 | switch (thisDiff.getOperation()) { | |
| 1112 | case INSERT: | |
| 1113 |
1
1. diffCleanupMerge : Changed increment from 1 to -1 → NO_COVERAGE |
countInsert++; |
| 1114 | textInsert.append(thisDiff.getText()); | |
| 1115 | prevEqual = null; | |
| 1116 | break; | |
| 1117 | case DELETE: | |
| 1118 |
1
1. diffCleanupMerge : Changed increment from 1 to -1 → NO_COVERAGE |
countDelete++; |
| 1119 | textDelete.append(thisDiff.getText()); | |
| 1120 | prevEqual = null; | |
| 1121 | break; | |
| 1122 | case EQUAL: | |
| 1123 |
3
1. diffCleanupMerge : negated conditional → NO_COVERAGE 2. diffCleanupMerge : changed conditional boundary → NO_COVERAGE 3. diffCleanupMerge : Replaced integer addition with subtraction → NO_COVERAGE |
if (countDelete + countInsert > 1) { |
| 1124 | ||
| 1125 |
2
1. diffCleanupMerge : negated conditional → NO_COVERAGE 2. diffCleanupMerge : negated conditional → NO_COVERAGE |
boolean bothTypes = countDelete != 0 && countInsert != 0; |
| 1126 | // Delete the offending records. | |
| 1127 | pointer.previous(); // Reverse direction. | |
| 1128 |
3
1. diffCleanupMerge : negated conditional → NO_COVERAGE 2. diffCleanupMerge : changed conditional boundary → NO_COVERAGE 3. diffCleanupMerge : Changed increment from -1 to 1 → NO_COVERAGE |
while (countDelete-- > 0) { |
| 1129 | pointer.previous(); | |
| 1130 |
1
1. diffCleanupMerge : removed call to java/util/ListIterator::remove → NO_COVERAGE |
pointer.remove(); |
| 1131 | } | |
| 1132 |
3
1. diffCleanupMerge : changed conditional boundary → NO_COVERAGE 2. diffCleanupMerge : Changed increment from -1 to 1 → NO_COVERAGE 3. diffCleanupMerge : negated conditional → NO_COVERAGE |
while (countInsert-- > 0) { |
| 1133 | pointer.previous(); | |
| 1134 |
1
1. diffCleanupMerge : removed call to java/util/ListIterator::remove → NO_COVERAGE |
pointer.remove(); |
| 1135 | } | |
| 1136 | ||
| 1137 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (bothTypes) { |
| 1138 | // Factor out any common prefixies. | |
| 1139 | commonlength = this.diffCommonPrefix(textInsert.toString(), textDelete.toString()); | |
| 1140 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (commonlength != 0) { |
| 1141 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (pointer.hasPrevious()) { |
| 1142 | thisDiff = pointer.previous(); | |
| 1143 | // Previous diff should have been an equality: thisDiff.getOperation() == Operation.EQUAL") | |
| 1144 |
1
1. diffCleanupMerge : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
thisDiff.setText(thisDiff.getText() + textInsert.substring(0, commonlength)); |
| 1145 | pointer.next(); | |
| 1146 | } else { | |
| 1147 |
1
1. diffCleanupMerge : removed call to java/util/ListIterator::add → NO_COVERAGE |
pointer.add(new Diff(Operation.EQUAL, |
| 1148 | textInsert.substring(0, commonlength))); | |
| 1149 | } | |
| 1150 | String substringIns = textInsert.substring(commonlength); | |
| 1151 |
1
1. diffCleanupMerge : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
textInsert.setLength(0); |
| 1152 | textInsert.append(substringIns); | |
| 1153 | String substringDel = textDelete.substring(commonlength); | |
| 1154 |
1
1. diffCleanupMerge : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
textDelete.setLength(0); |
| 1155 | textDelete.append(substringDel); | |
| 1156 | } | |
| 1157 | // Factor out any common suffixies. | |
| 1158 | commonlength = this.diffCommonSuffix(textInsert.toString(), textDelete.toString()); | |
| 1159 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (commonlength != 0) { |
| 1160 | thisDiff = pointer.next(); | |
| 1161 |
2
1. diffCleanupMerge : Replaced integer subtraction with addition → NO_COVERAGE 2. diffCleanupMerge : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
thisDiff.setText(textInsert.substring(textInsert.length() - commonlength) + thisDiff.getText()); |
| 1162 |
1
1. diffCleanupMerge : Replaced integer subtraction with addition → NO_COVERAGE |
String substringIns = textInsert.substring(0, textInsert.length() - commonlength); |
| 1163 |
1
1. diffCleanupMerge : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
textInsert.setLength(0); |
| 1164 | textInsert.append(substringIns); | |
| 1165 |
1
1. diffCleanupMerge : Replaced integer subtraction with addition → NO_COVERAGE |
String substringDel = textDelete.substring(0, textDelete.length() - commonlength); |
| 1166 |
1
1. diffCleanupMerge : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
textDelete.setLength(0); |
| 1167 | textDelete.append(substringDel); | |
| 1168 | pointer.previous(); | |
| 1169 | } | |
| 1170 | } | |
| 1171 | // Insert the merged records. | |
| 1172 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (!textDelete.isEmpty()) { |
| 1173 |
1
1. diffCleanupMerge : removed call to java/util/ListIterator::add → NO_COVERAGE |
pointer.add(new Diff(Operation.DELETE, textDelete.toString())); |
| 1174 | } | |
| 1175 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (!textInsert.isEmpty()) { |
| 1176 |
1
1. diffCleanupMerge : removed call to java/util/ListIterator::add → NO_COVERAGE |
pointer.add(new Diff(Operation.INSERT, textInsert.toString())); |
| 1177 | } | |
| 1178 | // Step forward to the equality. | |
| 1179 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
thisDiff = pointer.hasNext() ? pointer.next() : null; |
| 1180 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
} else if (prevEqual != null) { |
| 1181 | // Merge this equality with the previous one. | |
| 1182 |
1
1. diffCleanupMerge : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
prevEqual.setText(prevEqual.getText() + thisDiff.getText()); |
| 1183 |
1
1. diffCleanupMerge : removed call to java/util/ListIterator::remove → NO_COVERAGE |
pointer.remove(); |
| 1184 | thisDiff = pointer.previous(); | |
| 1185 | pointer.next(); // Forward direction | |
| 1186 | } | |
| 1187 | countInsert = 0; | |
| 1188 | countDelete = 0; | |
| 1189 |
1
1. diffCleanupMerge : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
textDelete.setLength(0); |
| 1190 |
1
1. diffCleanupMerge : removed call to java/lang/StringBuilder::setLength → NO_COVERAGE |
textInsert.setLength(0); |
| 1191 | prevEqual = thisDiff; | |
| 1192 | break; | |
| 1193 | } | |
| 1194 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
thisDiff = pointer.hasNext() ? pointer.next() : null; |
| 1195 | } | |
| 1196 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (diffs.getLast().getText().isEmpty()) { |
| 1197 | diffs.removeLast(); // Remove the dummy entry at the end. | |
| 1198 | } | |
| 1199 | ||
| 1200 | /* | |
| 1201 | * Second pass: look for single edits surrounded on both sides by equalities | |
| 1202 | * which can be shifted sideways to eliminate an equality. | |
| 1203 | * e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC | |
| 1204 | */ | |
| 1205 | boolean changes = false; | |
| 1206 | // Create a new iterator at the start. | |
| 1207 | // (As opposed to walking the current one back.) | |
| 1208 | pointer = diffs.listIterator(); | |
| 1209 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
Diff prevDiff = pointer.hasNext() ? pointer.next() : null; |
| 1210 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
thisDiff = pointer.hasNext() ? pointer.next() : null; |
| 1211 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
Diff nextDiff = pointer.hasNext() ? pointer.next() : null; |
| 1212 | ||
| 1213 | // Intentionally ignore the first and last element (don't need checking). | |
| 1214 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
while (nextDiff != null) { |
| 1215 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (prevDiff.getOperation() == Operation.EQUAL && |
| 1216 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
nextDiff.getOperation() == Operation.EQUAL) { |
| 1217 | // This is a single edit surrounded by equalities. | |
| 1218 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (thisDiff.getText().endsWith(prevDiff.getText())) { |
| 1219 | // Shift the edit over the previous equality. | |
| 1220 |
1
1. diffCleanupMerge : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
thisDiff.setText(prevDiff.getText() |
| 1221 | + thisDiff.getText().substring(0, thisDiff.getText().length() | |
| 1222 |
1
1. diffCleanupMerge : Replaced integer subtraction with addition → NO_COVERAGE |
- prevDiff.getText().length())); |
| 1223 |
1
1. diffCleanupMerge : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
nextDiff.setText(prevDiff.getText() + nextDiff.getText()); |
| 1224 | pointer.previous(); // Walk past nextDiff. | |
| 1225 | pointer.previous(); // Walk past thisDiff. | |
| 1226 | pointer.previous(); // Walk past prevDiff. | |
| 1227 |
1
1. diffCleanupMerge : removed call to java/util/ListIterator::remove → NO_COVERAGE |
pointer.remove(); // Delete prevDiff. |
| 1228 | pointer.next(); // Walk past thisDiff. | |
| 1229 | thisDiff = pointer.next(); // Walk past nextDiff. | |
| 1230 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
nextDiff = pointer.hasNext() ? pointer.next() : null; |
| 1231 | changes = true; | |
| 1232 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
} else if (thisDiff.getText().startsWith(nextDiff.getText())) { |
| 1233 | // Shift the edit over the next equality. | |
| 1234 |
1
1. diffCleanupMerge : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
prevDiff.setText(prevDiff.getText() + nextDiff.getText()); |
| 1235 |
1
1. diffCleanupMerge : removed call to com/jsql/model/injection/strategy/blind/patch/Diff::setText → NO_COVERAGE |
thisDiff.setText(thisDiff.getText().substring(nextDiff.getText().length()) |
| 1236 | + nextDiff.getText()); | |
| 1237 |
1
1. diffCleanupMerge : removed call to java/util/ListIterator::remove → NO_COVERAGE |
pointer.remove(); // Delete nextDiff. |
| 1238 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
nextDiff = pointer.hasNext() ? pointer.next() : null; |
| 1239 | changes = true; | |
| 1240 | } | |
| 1241 | } | |
| 1242 | prevDiff = thisDiff; | |
| 1243 | thisDiff = nextDiff; | |
| 1244 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
nextDiff = pointer.hasNext() ? pointer.next() : null; |
| 1245 | } | |
| 1246 | // If shifts were made, the diff needs reordering and another shift sweep. | |
| 1247 |
1
1. diffCleanupMerge : negated conditional → NO_COVERAGE |
if (changes) { |
| 1248 |
1
1. diffCleanupMerge : removed call to com/jsql/model/injection/strategy/blind/patch/DiffMatchPatch::diffCleanupMerge → NO_COVERAGE |
this.diffCleanupMerge(diffs); |
| 1249 | } | |
| 1250 | } | |
| 1251 | } | |
Mutations | ||
| 86 |
1.1 |
|
| 87 |
1.1 |
|
| 107 |
1.1 2.2 |
|
| 113 |
1.1 |
|
| 115 |
1.1 |
|
| 118 |
1.1 |
|
| 129 |
1.1 |
|
| 130 |
1.1 |
|
| 131 |
1.1 |
|
| 137 |
1.1 |
|
| 138 |
1.1 |
|
| 140 |
1.1 |
|
| 141 |
1.1 |
|
| 144 |
1.1 |
|
| 145 |
1.1 |
|
| 162 |
1.1 |
|
| 165 |
1.1 |
|
| 168 |
1.1 |
|
| 171 |
1.1 |
|
| 176 |
1.1 2.2 |
|
| 177 |
1.1 2.2 |
|
| 179 |
1.1 |
|
| 181 |
1.1 2.2 |
|
| 185 |
1.1 |
|
| 186 |
1.1 |
|
| 189 |
1.1 |
|
| 194 |
1.1 |
|
| 200 |
1.1 |
|
| 214 |
1.1 |
|
| 217 |
1.1 2.2 3.3 4.4 5.5 |
|
| 218 |
1.1 |
|
| 221 |
1.1 |
|
| 243 |
1.1 |
|
| 245 |
1.1 |
|
| 257 |
1.1 |
|
| 260 |
1.1 |
|
| 264 |
1.1 |
|
| 269 |
1.1 2.2 3.3 4.4 |
|
| 272 |
1.1 2.2 3.3 |
|
| 274 |
1.1 |
|
| 277 |
1.1 |
|
| 282 |
1.1 |
|
| 283 |
1.1 |
|
| 286 |
1.1 |
|
| 290 |
1.1 |
|
| 306 |
1.1 2.2 3.3 |
|
| 307 |
1.1 |
|
| 310 |
1.1 2.2 |
|
| 314 |
1.1 |
|
| 315 |
1.1 |
|
| 316 |
1.1 |
|
| 319 |
1.1 2.2 |
|
| 327 |
1.1 2.2 |
|
| 329 |
1.1 2.2 |
|
| 334 |
1.1 2.2 3.3 4.4 5.5 |
|
| 335 |
1.1 |
|
| 337 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 338 |
1.1 |
|
| 340 |
1.1 2.2 |
|
| 342 |
1.1 |
|
| 343 |
1.1 2.2 3.3 4.4 |
|
| 344 |
1.1 |
|
| 345 |
1.1 |
|
| 346 |
1.1 |
|
| 349 |
1.1 2.2 |
|
| 351 |
1.1 |
|
| 352 |
1.1 2.2 |
|
| 354 |
1.1 |
|
| 355 |
1.1 |
|
| 356 |
1.1 2.2 |
|
| 357 |
1.1 2.2 3.3 4.4 5.5 |
|
| 359 |
1.1 |
|
| 360 |
1.1 2.2 |
|
| 362 |
1.1 |
|
| 369 |
1.1 2.2 3.3 4.4 5.5 |
|
| 370 |
1.1 |
|
| 372 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 373 |
1.1 |
|
| 375 |
1.1 2.2 |
|
| 377 |
1.1 |
|
| 378 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 379 |
1.1 2.2 |
|
| 380 |
1.1 |
|
| 381 |
1.1 |
|
| 382 |
1.1 |
|
| 385 |
1.1 2.2 |
|
| 387 |
1.1 |
|
| 388 |
1.1 2.2 |
|
| 390 |
1.1 |
|
| 391 |
1.1 |
|
| 392 |
1.1 2.2 |
|
| 393 |
1.1 2.2 3.3 4.4 5.5 |
|
| 395 |
1.1 2.2 |
|
| 397 |
1.1 |
|
| 398 |
1.1 2.2 |
|
| 400 |
1.1 |
|
| 411 |
1.1 |
|
| 435 |
1.1 |
|
| 459 |
1.1 |
|
| 479 |
1.1 2.2 3.3 |
|
| 481 |
1.1 |
|
| 482 |
1.1 |
|
| 484 |
1.1 |
|
| 485 |
1.1 |
|
| 487 |
1.1 |
|
| 491 |
1.1 |
|
| 492 |
1.1 |
|
| 495 |
1.1 |
|
| 508 |
1.1 2.2 |
|
| 511 |
1.1 |
|
| 524 |
1.1 2.2 |
|
| 525 |
1.1 |
|
| 526 |
1.1 |
|
| 529 |
1.1 |
|
| 543 |
1.1 2.2 |
|
| 544 |
1.1 2.2 3.3 |
|
| 545 |
1.1 2.2 |
|
| 548 |
1.1 |
|
| 566 |
1.1 2.2 |
|
| 570 |
1.1 2.2 |
|
| 571 |
1.1 |
|
| 572 |
1.1 2.2 |
|
| 577 |
1.1 |
|
| 578 |
1.1 |
|
| 587 |
1.1 |
|
| 589 |
1.1 |
|
| 590 |
1.1 |
|
| 592 |
1.1 |
|
| 593 |
1.1 2.2 3.3 |
|
| 596 |
1.1 |
|
| 612 |
1.1 2.2 |
|
| 613 |
1.1 2.2 |
|
| 614 |
1.1 2.2 3.3 4.4 5.5 |
|
| 619 |
1.1 2.2 |
|
| 621 |
1.1 2.2 |
|
| 623 |
1.1 2.2 |
|
| 625 |
1.1 |
|
| 627 |
1.1 |
|
| 631 |
1.1 2.2 |
|
| 635 |
1.1 2.2 |
|
| 636 |
1.1 |
|
| 638 |
1.1 |
|
| 654 |
1.1 2.2 |
|
| 661 |
1.1 2.2 |
|
| 666 |
1.1 2.2 3.3 |
|
| 667 |
1.1 2.2 |
|
| 669 |
1.1 |
|
| 670 |
1.1 |
|
| 671 |
1.1 |
|
| 672 |
1.1 |
|
| 675 |
1.1 2.2 3.3 |
|
| 676 |
1.1 |
|
| 688 |
1.1 |
|
| 704 |
1.1 |
|
| 705 |
1.1 |
|
| 715 |
1.1 |
|
| 716 |
1.1 |
|
| 718 |
1.1 |
|
| 722 |
1.1 |
|
| 724 |
1.1 2.2 |
|
| 725 |
1.1 2.2 |
|
| 728 |
1.1 |
|
| 734 |
1.1 |
|
| 736 |
1.1 |
|
| 739 |
1.1 |
|
| 743 |
1.1 |
|
| 745 |
1.1 |
|
| 751 |
1.1 |
|
| 764 |
1.1 |
|
| 768 |
1.1 |
|
| 769 |
1.1 |
|
| 771 |
1.1 |
|
| 782 |
1.1 |
|
| 784 |
1.1 |
|
| 789 |
1.1 |
|
| 790 |
1.1 |
|
| 791 |
1.1 |
|
| 796 |
1.1 2.2 |
|
| 797 |
1.1 2.2 3.3 |
|
| 798 |
1.1 2.2 3.3 |
|
| 801 |
1.1 |
|
| 803 |
1.1 2.2 |
|
| 804 |
1.1 |
|
| 809 |
1.1 2.2 3.3 |
|
| 810 |
1.1 2.2 3.3 |
|
| 814 |
1.1 |
|
| 816 |
1.1 |
|
| 817 |
1.1 2.2 |
|
| 818 |
1.1 |
|
| 819 |
1.1 |
|
| 824 |
1.1 |
|
| 827 |
1.1 |
|
| 850 |
1.1 |
|
| 851 |
1.1 |
|
| 852 |
1.1 |
|
| 855 |
1.1 |
|
| 856 |
1.1 |
|
| 857 |
1.1 |
|
| 859 |
1.1 |
|
| 862 |
1.1 |
|
| 867 |
1.1 |
|
| 868 |
1.1 |
|
| 869 |
1.1 |
|
| 870 |
1.1 |
|
| 872 |
1.1 |
|
| 881 |
1.1 |
|
| 882 |
1.1 2.2 |
|
| 883 |
1.1 |
|
| 887 |
1.1 |
|
| 890 |
1.1 |
|
| 892 |
1.1 2.2 |
|
| 900 |
1.1 |
|
| 902 |
1.1 |
|
| 903 |
1.1 |
|
| 908 |
1.1 |
|
| 912 |
1.1 |
|
| 913 |
1.1 |
|
| 914 |
1.1 |
|
| 916 |
1.1 |
|
| 924 |
1.1 |
|
| 937 |
1.1 2.2 |
|
| 939 |
1.1 |
|
| 947 |
1.1 |
|
| 949 |
1.1 |
|
| 950 |
1.1 |
|
| 951 |
1.1 2.2 |
|
| 952 |
1.1 2.2 |
|
| 953 |
1.1 |
|
| 954 |
1.1 |
|
| 955 |
1.1 |
|
| 956 |
1.1 |
|
| 957 |
1.1 2.2 |
|
| 958 |
1.1 2.2 |
|
| 960 |
1.1 2.2 |
|
| 962 |
1.1 |
|
| 963 |
1.1 2.2 |
|
| 965 |
1.1 |
|
| 966 |
1.1 2.2 3.3 |
|
| 968 |
1.1 |
|
| 969 |
1.1 2.2 |
|
| 971 |
1.1 |
|
| 972 |
1.1 2.2 |
|
| 974 |
1.1 |
|
| 984 |
1.1 |
|
| 1002 |
1.1 |
|
| 1004 |
1.1 |
|
| 1007 |
1.1 2.2 3.3 4.4 |
|
| 1015 |
1.1 |
|
| 1022 |
1.1 |
|
| 1036 |
1.1 2.2 3.3 4.4 5.5 |
|
| 1041 |
1.1 2.2 |
|
| 1042 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 1047 |
1.1 |
|
| 1053 |
1.1 |
|
| 1056 |
1.1 |
|
| 1060 |
1.1 2.2 |
|
| 1063 |
1.1 |
|
| 1066 |
1.1 |
|
| 1070 |
1.1 |
|
| 1078 |
1.1 |
|
| 1087 |
1.1 |
|
| 1090 |
1.1 |
|
| 1091 |
1.1 |
|
| 1110 |
1.1 |
|
| 1113 |
1.1 |
|
| 1118 |
1.1 |
|
| 1123 |
1.1 2.2 3.3 |
|
| 1125 |
1.1 2.2 |
|
| 1128 |
1.1 2.2 3.3 |
|
| 1130 |
1.1 |
|
| 1132 |
1.1 2.2 3.3 |
|
| 1134 |
1.1 |
|
| 1137 |
1.1 |
|
| 1140 |
1.1 |
|
| 1141 |
1.1 |
|
| 1144 |
1.1 |
|
| 1147 |
1.1 |
|
| 1151 |
1.1 |
|
| 1154 |
1.1 |
|
| 1159 |
1.1 |
|
| 1161 |
1.1 2.2 |
|
| 1162 |
1.1 |
|
| 1163 |
1.1 |
|
| 1165 |
1.1 |
|
| 1166 |
1.1 |
|
| 1172 |
1.1 |
|
| 1173 |
1.1 |
|
| 1175 |
1.1 |
|
| 1176 |
1.1 |
|
| 1179 |
1.1 |
|
| 1180 |
1.1 |
|
| 1182 |
1.1 |
|
| 1183 |
1.1 |
|
| 1189 |
1.1 |
|
| 1190 |
1.1 |
|
| 1194 |
1.1 |
|
| 1196 |
1.1 |
|
| 1209 |
1.1 |
|
| 1210 |
1.1 |
|
| 1211 |
1.1 |
|
| 1214 |
1.1 |
|
| 1215 |
1.1 |
|
| 1216 |
1.1 |
|
| 1218 |
1.1 |
|
| 1220 |
1.1 |
|
| 1222 |
1.1 |
|
| 1223 |
1.1 |
|
| 1227 |
1.1 |
|
| 1230 |
1.1 |
|
| 1232 |
1.1 |
|
| 1234 |
1.1 |
|
| 1235 |
1.1 |
|
| 1237 |
1.1 |
|
| 1238 |
1.1 |
|
| 1244 |
1.1 |
|
| 1247 |
1.1 |
|
| 1248 |
1.1 |