Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for duplicate xml elements #402

Merged
merged 2 commits into from
May 18, 2021

Conversation

oturpe
Copy link
Contributor

@oturpe oturpe commented May 13, 2021

Draft fix of #401

As an example, duplicate checking for two elements is added. Using this simple system, checking all elements requires replicating the code for each checked field. Solution with less replication would require a new data structure and passing it around: instead of enumerated problems like AS_APP_PROBLEM_DUPLICATE_PROJECT_LICENSE, some kind of generic duplicate problem entry that takes element name as input.

Posting this draft for review, because I am really new to this codebase and cannot say what would be best way to proceed:

  1. Replicate the simple solution for all fields that can only appear once
  2. Develop the generic solution
  3. Only check project_license duplicates, as that is what was reported in Validation should not accept multiple project_license elements #401 and there the root of the problem is that even if a project may be under multiple licenses, there can only be one license field and separate syntax for encoding everything in there must be used.

Comments welcome.

libappstream-glib/as-app.c Outdated Show resolved Hide resolved
libappstream-glib/as-app.c Outdated Show resolved Hide resolved
@hughsie
Copy link
Owner

hughsie commented May 13, 2021

A few nits, but looks basically what I would have done, so good job.

@oturpe oturpe force-pushed the duplicate-element-validation branch from b330dfe to 441c1b3 Compare May 13, 2021 20:25
@oturpe
Copy link
Contributor Author

oturpe commented May 13, 2021

Formatting fixed. A test case failed, apparently the "bad file" test already had a test file that had these problems, now the asserts need to be fixed. I will see to that soon.

AppStream license syntax allows constructs of form "LICENSE1 AND
LICENSE2". It is possible to confuse this with writing multiple license
xml elements in a metainfo file. In order to spot this type of error,
duplicate detection is added for xml elements metadata_license and
project_license.
@oturpe oturpe force-pushed the duplicate-element-validation branch from 441c1b3 to f883383 Compare May 17, 2021 19:38
@oturpe
Copy link
Contributor Author

oturpe commented May 17, 2021

Tests added. In absence of further comments about which elements should be tested for duplicates, I left the scope as it was initially: only the license fields.

@oturpe
Copy link
Contributor Author

oturpe commented May 17, 2021

Travis CI build failed, but to me that looks like an unrelated issue, as if something is generated without strict ordering, but is checked against fixed expectation:

Bail out! As:ERROR:../libappstream-builder/asb-self-test.c:524:asb_test_context_func: assertion failed (error == NULL):
--- /tmp/b	2021-05-17 19:42:30.984710347 +0000
+++ /tmp/a	2021-05-17 19:42:30.984710347 +0000
@@ -24,8 +24,8 @@
 <name>App</name>
 <summary>A test application</summary>
 <description><p>Long description goes here.</p></description>
-<icon type="cached" height="128" width="128">app.png</icon>
 <icon type="cached" height="64" width="64">app.png</icon>
+<icon type="cached" height="128" width="128">app.png</icon>
 <categories>
 <category>Profiling</category>
 <category>System</category>
 (-g-type-private--GTypeFlags, 0)

@hughsie
Copy link
Owner

hughsie commented May 17, 2021

but to me that looks like an unrelated issue

Agreed! Could I be cheeky and ask you to add the fix for that to this branch please? It should just be reordering the expected lines in asb-self-test.c. Thanks!

Apparently, write ordering of some field schanged at some point, but the
test case was not updated. Updating to allow Travis CI to pass.
@oturpe
Copy link
Contributor Author

oturpe commented May 17, 2021

That error is now fixed, but another one was hidden behind it:

Bail out! As:ERROR:../libappstream-builder/asb-self-test.c:628:asb_test_context_func: assertion failed: (g_file_test ("/tmp/asbuilder/temp/icons/64x64/app.png", G_FILE_TEST_EXISTS))

--- stderr ---
**
As:ERROR:../libappstream-builder/asb-self-test.c:628:asb_test_context_func: assertion failed: (g_file_test ("/tmp/asbuilder/temp/icons/64x64/app.png", G_FILE_TEST_EXISTS))
-------

@oturpe oturpe changed the title Draft: Add validation for duplicate xml elements Add validation for duplicate xml elements May 17, 2021
@hughsie
Copy link
Owner

hughsie commented May 18, 2021

That error is now fixed, but another one was hidden behind it:

Okay, I can look at that later. Thanks for the fixes!

@hughsie hughsie merged commit 6d6b8f4 into hughsie:master May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants