diff --git a/custom_json_diff/bom_diff_template.j2 b/custom_json_diff/bom_diff_template.j2 index 3314d0a..415a92b 100644 --- a/custom_json_diff/bom_diff_template.j2 +++ b/custom_json_diff/bom_diff_template.j2 @@ -96,7 +96,7 @@ {{ bom_1 }} {{ bom_2 }} - {% if not (diff_apps_1 or diff_apps_2 or diff_frameworks_1 or diff_frameworks_2 or diff_lib_1 or diff_lib_2 or diff_other_1 or diff_other_2 or diff_vdrs_1 or diff_vdrs_2) %} + {% if diff_status == 0 %} No differences found. @@ -432,7 +432,7 @@ Components - {% if not (common_apps or common_frameworks or common_lib or common_other) %} + {% if not (common_apps or common_frameworks or common_lib or common_other or common_services or common_deps or common_vdrs) %} No commonalities. diff --git a/custom_json_diff/custom_diff.py b/custom_json_diff/custom_diff.py index 6d83f34..07f3518 100644 --- a/custom_json_diff/custom_diff.py +++ b/custom_json_diff/custom_diff.py @@ -43,7 +43,7 @@ def compare_dicts(options: Options) -> Tuple[int, FlatDicts | BomDicts, FlatDict return 1, json_1_data, json_2_data -def export_html_report(outfile: str, diffs: Dict, j1: BomDicts, j2: BomDicts, options: Options) -> None: +def export_html_report(outfile: str, diffs: Dict, j1: BomDicts, j2: BomDicts, options: Options, status: int) -> None: if options.report_template: template_file = options.report_template else: @@ -92,6 +92,7 @@ def export_html_report(outfile: str, diffs: Dict, j1: BomDicts, j2: BomDicts, op stats=stats_summary, comp_only=options.comp_only, metadata=metadata_results, + diff_status=status, ) with open(outfile, "w", encoding="utf-8") as f: f.write(report_result) @@ -146,7 +147,7 @@ def load_json(json_file: str, options: Options) -> FlatDicts | BomDicts: logger.error("Invalid JSON: %s", json_file) sys.exit(1) if options.bom_diff: - data = sort_dict_lists(data, ["url", "content", "ref", "name", "value"]) + data = sort_dict_lists(data, ["bom-ref", "id", "url", "content", "ref", "name", "value"]) data = filter_dict(data, options).to_dict(unflat=True) return BomDicts(options, json_file, data, {}) return filter_dict(data, options) @@ -178,7 +179,7 @@ def report_results(status: int, diffs: Dict, options: Options, j1: BomDicts | No return if options.bom_diff: report_file = options.output.replace(".json", "") + ".html" - export_html_report(report_file, diffs, j1, j2, options) # type: ignore + export_html_report(report_file, diffs, j1, j2, options, status) # type: ignore def sort_dict_lists(result: Dict, sort_keys: List[str]) -> Dict: diff --git a/custom_json_diff/custom_diff_classes.py b/custom_json_diff/custom_diff_classes.py index 8dff555..94ef5e8 100644 --- a/custom_json_diff/custom_diff_classes.py +++ b/custom_json_diff/custom_diff_classes.py @@ -432,11 +432,11 @@ def compare_bom_refs(v1: str, v2: str) -> bool: def compare_date(dt1: str, dt2: str, comparator: str): """Compares two dates""" - if dt1 == dt2 or (not dt1 and not dt2): + if not dt1 and not dt2: return True try: - date_1 = datetime.fromisoformat(dt1) - date_2 = datetime.fromisoformat(dt2) + date_1 = datetime.fromisoformat(dt1).date() + date_2 = datetime.fromisoformat(dt2).date() match comparator: case "<": return date_1 < date_2 @@ -454,7 +454,7 @@ def compare_date(dt1: str, dt2: str, comparator: str): def compare_vdr_new_versions(vdr_1: BomVdr, vdr_2: BomVdr) -> bool: return all((vdr_1.affects == vdr_2.affects, - compare_date(vdr_1.updated, vdr_2.updated, "<"), + (not vdr_1.updated or compare_date(vdr_1.updated, vdr_2.updated, "<=")), compare_bom_refs(vdr_1.bom_ref, vdr_2.bom_ref))) diff --git a/pyproject.toml b/pyproject.toml index 25c37d3..bcc91fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "custom-json-diff" -version = "1.5.5" +version = "1.5.6" description = "Custom JSON and CycloneDx BOM diffing and comparison tool." authors = [ { name = "Caroline Russell", email = "caroline@appthreat.dev" },