Skip to content

Commit

Permalink
fix: null vs. undefined vs. falsy checks, report description was inco…
Browse files Browse the repository at this point in the history
…rrectly verified (was using title), error first discovered in log provided at #402
  • Loading branch information
danielweck committed Sep 18, 2024
1 parent 4c0ed5e commit 14513cf
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 25 deletions.
3 changes: 2 additions & 1 deletion packages/ace-axe-runner-electron/bin/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ var args = [].concat(path.resolve(__dirname, "../lib/cli.js"), process.argv.slic

var child = proc.spawn(electron, args, { stdio: 'inherit', windowsHide: false })
child.on('close', function (code, signal) {
if (code === null) {
if (code === null || code === undefined) {
console.error(electron, 'exited with signal', signal)
process.exit(1)
return;
}
process.exit(code)
})
Expand Down
6 changes: 3 additions & 3 deletions packages/ace-core/src/checker/checker-chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ async function checkSingle(spineItem, epub, lang, axeRunner) {
Object.getOwnPropertyNames(results.data).forEach((key) => {
if (!Array.isArray(results.data[key])) return;
results.data[key].forEach((item) => {
if (item.src !== undefined) {
if (item.src) {
if (Array.isArray(item.src)) {
item.src = item.src.map((srcItem) => {
if (srcItem.src !== undefined) {
if (srcItem.src) {
if (LOG_DEBUG_URLS) {
console.log("----- ITEMs SRC 1");
console.log(srcItem.src);
Expand Down Expand Up @@ -161,7 +161,7 @@ async function checkSingle(spineItem, epub, lang, axeRunner) {
console.log(item.src);
}
}
if (item.cfi !== undefined) {
if (item.cfi) {
if (LOG_DEBUG_URLS) {
console.log("----- CFI 1");
console.log(spineItem.relpath);
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/checker/checker-epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const KB_BASE = 'http://kb.daisy.org/publishing/';
function asString(arrayOrString) {
if (Array.isArray(arrayOrString) && arrayOrString.length > 0) {
return asString(arrayOrString[0]);
} else if (arrayOrString !== undefined) {
} else if (arrayOrString) {
return arrayOrString.toString().trim();
}
return '';
Expand Down Expand Up @@ -71,7 +71,7 @@ function checkMetadata(assertions, epub) {
for (const name in a11yMetadata.A11Y_META) {
const meta = a11yMetadata.A11Y_META[name];
var values = epub.metadata[name];
if (values === undefined) {
if (!values) {
// Report missing metadata if it is required or recommended
if (meta.required) assertions.withAssertions(newMetadataAssertion(name));
if (meta.recommended) assertions.withAssertions(newMetadataAssertion(name, 'moderate'));
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/checker/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function consolidate(results, report) {
}
return undefined;
}))
.filter(e => e !== undefined);
.filter(e => e);
report.addHeadings(headings);
// Aggregated array of the HTML outlines
const htmlOutlines = []
Expand All @@ -36,7 +36,7 @@ function consolidate(results, report) {
}
return undefined;
}))
.filter(e => e !== undefined);
.filter(e => e);
report.addHTMLOutlines(htmlOutlines);
return report;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/core/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function ace(epubPath, options, axeRunner) {
if (!fs.existsSync(options.tmpdir)) {
fs.ensureDirSync(options.tmpdir);
}
} else if (options.tmpdir === undefined) {
} else if (!options.tmpdir) {
options.tmpdir = tmp.dirSync({ unsafeCleanup: true }).name;
}
if (typeof options.outdir === 'string') {
Expand All @@ -72,7 +72,7 @@ module.exports = function ace(epubPath, options, axeRunner) {
.then(report => checker.check(epub, report, options.lang, axeRunner))
// Process the Results
.then((report) => {
if (options.outdir === undefined) {
if (!options.outdir) {
report.cleanData();
process.stdout.write(`${JSON.stringify(report.json, null, ' ')}\n`);
return report;
Expand Down
6 changes: 3 additions & 3 deletions packages/ace-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function initRoutes() {
// return the job information
function getJob(req, res, next) {
var jobdata = joblist.find(jobdata => jobdata.internal.id === req.params.jobid);
if (jobdata == undefined || jobdata == null) {
if (!jobdata) {
res.sendStatus(404); // not found
}
else {
Expand All @@ -135,7 +135,7 @@ function getJobs(req, res, next) {

// return the job information
function postJob(req, res, next) {
if (req.file == undefined) {
if (!req.file) {
res.sendStatus(400); // bad request
}
else {
Expand Down Expand Up @@ -164,7 +164,7 @@ function postJob(req, res, next) {
// return the report as either a zipfile or a json object, depending on what was specifically requested
function getReport(req, res) {
var jobdata = joblist.find(jobdata => jobdata.internal.id === req.params.jobid);
if (jobdata == undefined || jobdata == null) {
if (!jobdata) {
res.sendStatus(404); // not found
}
else {
Expand Down
10 changes: 5 additions & 5 deletions packages/ace-report/src/report-builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function withTestSubject(obj, url, title = '', version='', identifier = '', meta
const testSubject = { url };
if (title.length > 0) testSubject['dct:title'] = title;
if (identifier.length > 0) testSubject['dct:identifier'] = identifier;
if (metadata !== undefined && metadata != null) testSubject.metadata = metadata;
if (links !== undefined && links != null) testSubject.links = links;
if (metadata) testSubject.metadata = metadata;
if (links) testSubject.links = links;
if (version && typeof version === "string" && version.length > 0) testSubject.epubVersion = version;
obj['earl:testSubject'] = testSubject;
return obj;
Expand Down Expand Up @@ -91,8 +91,8 @@ class ReportBuilder {
this._json = {
'@type': 'earl:report',
'@context': 'http://daisy.github.io/ace/ace-report-1.0.jsonld',
'dct:title': (title == null) ? '' : title.toString(),
'dct:description': (title == null) ? '' : description.toString(),
'dct:title': !title ? '' : title.toString(),
'dct:description': !description ? '' : description.toString(),
'dct:date': new Date().toLocaleString(),
'earl:assertedBy': {
'@type': 'earl:software',
Expand Down Expand Up @@ -171,7 +171,7 @@ class ReportBuilder {
}
withTestSubject(url, title, version, identifier, metadata, links) {
var url_ = url;
if (this.outdir !== undefined && this.outdir != "" && reportConfig["use-relative-paths"]) {
if (this.outdir && reportConfig["use-relative-paths"]) {
url_ = path.relative(this.outdir, url);
}
withTestSubject(this._json, url_, title, version, identifier, metadata, links);
Expand Down
2 changes: 1 addition & 1 deletion packages/ace-report/src/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module.exports = class Report {
}
copyData(outdir) {
winston.info("Copying data");
if (this.json.data === null) return Promise.resolve();
if (!this.json.data) return Promise.resolve();
return fs.pathExists(outdir)
.then((exists) => {
if (!exists) return fs.ensureDirSync(outdir);
Expand Down
4 changes: 2 additions & 2 deletions packages/epub-utils/src/epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function unzip(unzipDir, path, useLegacyZipLib) {
}

async function retryUnzip(unzipDir, epub, error) {
if (error.message === undefined) throw error;
if (!error.message) throw error;
winston.info('Trying to repair the archive and unzip again...');
try {
// Detect 'invalid comment length' errors
Expand Down Expand Up @@ -128,7 +128,7 @@ class EPUB {
}

async extract(unzipDir) {
if (this.basedir !== undefined) {
if (this.basedir) {
return this;
} else if (this.expanded) {
winston.verbose('EPUB is already unpacked');
Expand Down
2 changes: 1 addition & 1 deletion scripts/translate-scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const srcFolderPath = args[0];
const jsonFilePath = args[1];

function isNullOrUndefined(val) {
return val === undefined && val === null;
return val === undefined || val === null;
}

function sortObject(obj) {
Expand Down
6 changes: 3 additions & 3 deletions tests/data/report/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@
tr.append(tdImage);


var tdAlt = (image.alt === undefined) ?
var tdAlt = !image.alt ?
$('<td class="missing">N/A</td>')
: $('<td>' + image.alt + '</td>');
tr.append(tdAlt);

var tdDescribedby = (image.describedby === undefined) ?
var tdDescribedby = !image.describedby ?
$('<td class="missing">N/A</td>')
: $('<td>' + image.describedby + '</td>');
tr.append(tdDescribedby);

var tdFigcaption = (image.figcaption === undefined) ?
var tdFigcaption = !image.figcaption ?
$('<td class="missing">N/A</td>')
: $('<td>' + image.figcaption + '</td>');
tr.append(tdFigcaption);
Expand Down

0 comments on commit 14513cf

Please sign in to comment.