Commit 63242d9
fix(spdx-utils): Make license choice matching order-dependent
ORT had an architectural mismatch where `SpdxCompoundExpression` used
order-invariant equality ("MIT OR Apache-2.0" == "Apache-2.0 OR
MIT"), but the license choice matching used order-dependent matching
based on strings.
That is, if the expression contained "MIT OR Apache-2.0" but the user
gave "Apache-2.0 OR MIT", the string match failed, triggering a
fallback that rebuilt the expression by OR-ing all valid choices.
With multiple license choices, this caused exponential expression
growth (> 1000 characters in length).
This solution replaces the string-based algorithm with set-based
operations in `replaceSubexpressionWithChoice()`:
1. Decompose expressions into a set using `validChoices()`.
2. Remove dismissed choices from the set (no string operations).
3. Rebuild from remaining choices with controlled reduction.
4. Only recurse to AND-children if the sub-expression is actually
contained in a child to prevent inappropriate recursion for the
entire expression or derived sub-expression choices.
Since sets are order-invariant ({A,B} == {B,A}), both orderings
execute identical code paths, guaranteeing deterministic behavior.
Fixes #10888.
Signed-off-by: Antoni <168914426+cow-lang@users.noreply.github.com>
Co-authored-by: Sebastian Schuberth <sebastian@doubleopen.org>1 parent be610e3 commit 63242d9
File tree
2 files changed
+75
-13
lines changed- utils/spdx/src
- main/kotlin
- test/kotlin
2 files changed
+75
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
359 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
360 | 384 | | |
361 | 385 | | |
362 | 386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
126 | 137 | | |
127 | 138 | | |
128 | 139 | | |
| |||
199 | 210 | | |
200 | 211 | | |
201 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
202 | 240 | | |
203 | 241 | | |
204 | 242 | | |
| |||
0 commit comments