Skip to content

Commit a4d7084

Browse files
committed
bug:SP-3626 Fixes winnowing parsing issue
1 parent d3e0756 commit a4d7084

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Upcoming changes...
13+
14+
## [0.12.0] - 2025-11-03
1315
### Added
1416
- `calculateOppositeLineEndingHash()` method in `WinnowingUtils` to compute hash with opposite line endings (Unix ↔ Windows)
1517
- FH2 hash included in WFP output format as `fh2=<hash>`
1618
- Support for detecting CRLF (Windows), LF (Unix), and CR (legacy Mac) line endings
19+
### Fixed
20+
- Fixed WFP parsing issue
1721

1822
## [0.11.0] - 2025-05-26
1923
### Added
@@ -126,4 +130,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
126130
[0.9.0]: https://github.com/scanoss/scanoss.java/compare/v0.8.1...v0.9.0
127131
[0.10.0]: https://github.com/scanoss/scanoss.java/compare/v0.9.0...v0.10.0
128132
[0.10.1]: https://github.com/scanoss/scanoss.java/compare/v0.10.0...v0.10.1
129-
[0.11.0]: https://github.com/scanoss/scanoss.java/compare/v0.10.1...v0.11.0
133+
[0.11.0]: https://github.com/scanoss/scanoss.java/compare/v0.10.1...v0.11.0
134+
[0.12.0]: https://github.com/scanoss/scanoss.java/compare/v0.11.0...v0.12.0

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.scanoss</groupId>
88
<artifactId>scanoss</artifactId>
9-
<version>0.11.0</version>
9+
<version>0.12.0</version>
1010
<packaging>jar</packaging>
1111
<name>scanoss.java</name>
1212
<url>https://github.com/scanoss/scanoss.java</url>

src/main/java/com/scanoss/Winnowing.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ public String wfpForContents(@NonNull String filename, Boolean binFile, byte[] c
194194
if (lastLine != line) {
195195
int obLength = outputBuilder.length();
196196
if (obLength > 0) {
197-
if (snippetLimit > 0 && obLength > snippetLimit) {
198-
log.debug("Skipping snippet line as it's too big ({}): {}", filename, outputBuilder);
199-
} else {
200-
wfpBuilder.append(outputBuilder).append("\n");
201-
}
197+
wfpBuilder.append(outputBuilder).append("\n");
202198
}
203199
outputBuilder.delete(0, obLength);
204200
outputBuilder.append(String.format("%d=%s", line, minHashHex));
@@ -216,11 +212,7 @@ public String wfpForContents(@NonNull String filename, Boolean binFile, byte[] c
216212
}
217213
int obLength = outputBuilder.length();
218214
if (obLength > 0) {
219-
if (snippetLimit > 0 && obLength > snippetLimit) {
220-
log.debug("Skipping snippet line as it's too big ({}) {} - {}: {}", filename, snippetLimit, obLength, outputBuilder);
221-
} else {
222-
wfpBuilder.append(outputBuilder).append("\n");
223-
}
215+
wfpBuilder.append(outputBuilder).append("\n");
224216
}
225217
return wfpBuilder.toString();
226218
}
@@ -288,6 +280,21 @@ private Boolean skipSnippets(@NonNull String filename, char[] contents) {
288280
}
289281
}
290282
}
283+
// Check if first line is too long (matches Python implementation)
284+
int firstLineEnd = 0;
285+
for (int i = 0; i < contents.length; i++) {
286+
if (contents[i] == '\n') {
287+
firstLineEnd = i;
288+
break;
289+
}
290+
}
291+
if (firstLineEnd == 0) {
292+
firstLineEnd = contents.length; // No newline found, use entire content length
293+
}
294+
if (snippetLimit > 0 && firstLineEnd > snippetLimit) {
295+
log.trace("Skipping snippets due to first line being too long: {} - {} chars", filename, firstLineEnd);
296+
return true;
297+
}
291298
return false;
292299
}
293300

0 commit comments

Comments
 (0)