-
Notifications
You must be signed in to change notification settings - Fork 29
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
fix: Removed STIG filename filters #260
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1646,7 +1646,7 @@ function uploadStigs(n) { | |
let input = document.getElementById("form-file-file") | ||
let file = input.files[0] | ||
let extension = file.name.substring(file.name.lastIndexOf(".")+1) | ||
if (extension === 'xml') { | ||
if (extension.toLowerCase() === 'xml') { | ||
let formEl = fp.getForm().getEl().dom | ||
let formData = new FormData(formEl) | ||
formData.set('replace', 'true') | ||
|
@@ -1691,7 +1691,7 @@ function uploadStigs(n) { | |
|
||
let contents = await parentZip.loadAsync(f) | ||
let fns = Object.keys(contents.files) | ||
let xmlMembers = fns.filter( fn => fn.toLowerCase().endsWith('xccdf.xml') || fn.toLowerCase().endsWith('benchmark.xml') ) | ||
let xmlMembers = fns.filter( fn => fn.toLowerCase().endsWith('.xml')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you said, this ends up throwing all XML members to the API and makes the API sort things out. Instead of just throwing everything over the wall, it might be more efficient (for the API at least) and a better user experience (in the client) to implement basic vetting of the file in the client. Only send the API something we reasonably think is valid. Maybe we can iterate to that. I haven't run this client code yet, maybe this is acceptable for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'll leave this as something we will iterate too if needed |
||
let zipMembers = fns.filter( fn => fn.toLowerCase().endsWith('.zip') ) | ||
for (let x=0,l=xmlMembers.length; x<l; x++) { | ||
let xml = xmlMembers[x] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do need to throw an error here so the caller knows something went wrong. I think this try block covers too many operations, some of which should cause an immediate catch/throw and some that should not. I believe you're trying to avoid bombing out completely if a particular member fails parsing. The answer is to use nested try blocks. Maybe surround line 110 with try/catch and handle the error there without throwing to the outer block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added specific try/catch blocks to handle parsing errors.