cda-schematron-validator 1.0.7 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # [cda-schematron-validator](https://github.com/priyaranjan-tokachichu/cda-schematron-validator)
2
2
  ## Release History
3
3
  Starting release history with 1.0.7
4
+ ### 1.0.10
5
+ - Fix null context issue associated with assertions within assertions
6
+ - Skip abstract rules associated with assertions within assertions
7
+ ### 1.0.9
8
+ - Fixed the bug introduced in 1.0.8 trying to adjust to different data types of the return value
9
+ - Changed variable names to improve understanding of the process
10
+ ### 1.0.8
11
+ - Bug fix identifying the ignored errors
4
12
  ### 1.0.7
5
13
  - Added async validate function `validateAsync`
6
14
  - Added `testsAsync` to test `validateAsync`
package/SECURITY.md ADDED
@@ -0,0 +1,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ All releases within a major version will be supported with security updates. The first release from 1.x.x version is 1.0.7.
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 1.0.7 | :white_check_mark: |
10
+ | 1.0.6 | :x: |
11
+ | 1.0.5 | :x: |
12
+ | 1.0.4 | :x: |
13
+ | 1.0.3 | :x: |
14
+ | 1.0.2 | :x: |
15
+ | 1.0.1 | :x: |
16
+ | 1.0.0 | :x: |
17
+
18
+ ## Reporting a Vulnerability
19
+
20
+ Please, open an issue with the vulnerability discovered. If possible open a branch from main,
21
+ add a fix, and open a PR. I will review the security vulnerability and merge the PR if it is accepted.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cda-schematron-validator",
3
- "version": "1.0.7",
3
+ "version": "1.0.10",
4
4
  "description": "Fork of Eric Wadkins' javascript implementation of schematron testing for C-CDA XML documents. This includes bug fixes and some house keeping.",
5
5
  "main": "validator.js",
6
6
  "scripts": {
package/validator.js CHANGED
@@ -101,14 +101,14 @@ function validate(xml, schematron, options = {}) {
101
101
  const ruleObject = ruleAssertionMap[ruleId];
102
102
  if (_get(ruleObject, 'abstract')) {
103
103
  continue;
104
- }
104
+ }
105
105
  const context = _get(ruleObject, 'context');
106
106
  const assertionsAndExtensions = _get(ruleObject, 'assertionsAndExtensions') || [];
107
107
  let failedAssertions = checkRule(xmlDoc, context, assertionsAndExtensions, options);
108
108
  for (let j = 0; j < failedAssertions.length; j++) {
109
109
  const assertionObject = failedAssertions[j];
110
110
  const { type, assertionId, test, simplifiedTest, description, errorMessage, results } = assertionObject;
111
- if (!results.ignored) {
111
+ if (Array.isArray(results)) {
112
112
  for (let k = 0; k < results.length; k++) {
113
113
  const resultObject = results[k];
114
114
  const { result, line, path, xml } = resultObject;
@@ -135,7 +135,7 @@ function validate(xml, schematron, options = {}) {
135
135
  }
136
136
  }
137
137
  }
138
- else {
138
+ else if (results.ignored) {
139
139
  let obj = {
140
140
  errorMessage: errorMessage,
141
141
  type: type,
@@ -169,7 +169,7 @@ function checkRule(xmlDoc, originalContext, assertionsAndExtensions, options) {
169
169
  const includeWarnings = options.includeWarnings === undefined ? true : options.includeWarnings;
170
170
  const resourceDir = options.resourceDir || './';
171
171
  const xmlSnippetMaxLength = options.xmlSnippetMaxLength === undefined ? 200 : options.xmlSnippetMaxLength;
172
- let results = [];
172
+ let failedAssertions = [];
173
173
  const context = options.contextOverride || originalContext;
174
174
  // Determine the sections within context, load selected section from cache if possible
175
175
  let selected = contextMap[context];
@@ -194,19 +194,26 @@ function checkRule(xmlDoc, originalContext, assertionsAndExtensions, options) {
194
194
 
195
195
  // Extract values from external document and modify test if a document call is made
196
196
  let originalTest = test;
197
+ let simplifiedTest = null;
197
198
  try {
198
199
  test = includeExternalDocument(test, resourceDir);
199
200
  }
200
201
  catch (err) {
201
- return { ignored: true, errorMessage: err.message };
202
- }
203
-
204
- let simplifiedTest = null;
202
+ failedAssertions.push({
203
+ type: level,
204
+ assertionId: id,
205
+ test: originalTest,
206
+ simplifiedTest: simplifiedTest,
207
+ description: description,
208
+ results: { ignored: true, errorMessage: err.message }
209
+ });
210
+ continue;
211
+ }
205
212
  if (originalTest !== test) {
206
213
  simplifiedTest = test;
207
214
  }
208
215
  if (level === 'error' || includeWarnings) {
209
- results.push({
216
+ failedAssertions.push({
210
217
  type: level,
211
218
  assertionId: id,
212
219
  test: originalTest,
@@ -225,12 +232,19 @@ function checkRule(xmlDoc, originalContext, assertionsAndExtensions, options) {
225
232
  if (!subAssertionsAndExtensions) {
226
233
  continue;
227
234
  }
228
- const newRuleObject = ruleAssertionMap[extensionRule];
235
+ const newRuleObject = ruleAssertionMap[extensionRule];
236
+ if (_get(newRuleObject, 'abstract')) {
237
+ continue;
238
+ }
229
239
  const newContext = newRuleObject.context;
230
- results = results.concat(checkRule(xmlDoc, newContext, subAssertionsAndExtensions, options));
240
+ if (!newContext) {
241
+ continue;
242
+ }
243
+ const failedSubAssertions = checkRule(xmlDoc, newContext, subAssertionsAndExtensions, options);
244
+ failedAssertions.push(...failedSubAssertions);
231
245
  }
232
246
  }
233
- return results;
247
+ return failedAssertions;
234
248
  }
235
249
 
236
250
  async function validateAsync(xml, schematron, options = {}) {
@@ -310,18 +324,17 @@ async function validateAsync(xml, schematron, options = {}) {
310
324
  }
311
325
  const context = _get(ruleObject, 'context');
312
326
  const assertionsAndExtensions = _get(ruleObject, 'assertionsAndExtensions') || [];
313
- let failedAssertions;
314
327
  try {
315
328
  failedAssertions = await checkRulePromise(xmlDoc, context, assertionsAndExtensions, options);
316
329
  }
317
330
  catch (errorInRuleCheck) {
318
331
  console.log(errorInRuleCheck);
319
332
  continue;
320
- }
333
+ }
321
334
  for (let j = 0; j < failedAssertions.length; j++) {
322
335
  const assertionObject = failedAssertions[j];
323
336
  const { type, assertionId, test, simplifiedTest, description, errorMessage, results } = assertionObject;
324
- if (!results.ignored) {
337
+ if (Array.isArray(results)) {
325
338
  for (let k = 0; k < results.length; k++) {
326
339
  const resultObject = results[k];
327
340
  const { result, line, path, xml } = resultObject;
@@ -348,7 +361,7 @@ async function validateAsync(xml, schematron, options = {}) {
348
361
  }
349
362
  }
350
363
  }
351
- else {
364
+ else if (results.ignored) {
352
365
  let obj = {
353
366
  errorMessage: errorMessage,
354
367
  type: type,
@@ -381,10 +394,11 @@ function checkRulePromise(xmlDoc, originalContext, assertionsAndExtensions, opti
381
394
  // Context cache
382
395
  const resultCapture = new Promise((resolve, reject) => {
383
396
  try {
397
+ // Context cache
384
398
  const includeWarnings = options.includeWarnings === undefined ? true : options.includeWarnings;
385
399
  const resourceDir = options.resourceDir || './';
386
400
  const xmlSnippetMaxLength = options.xmlSnippetMaxLength === undefined ? 200 : options.xmlSnippetMaxLength;
387
- let results = [];
401
+ let failedAssertions = [];
388
402
  const context = options.contextOverride || originalContext;
389
403
  // Determine the sections within context, load selected section from cache if possible
390
404
  let selected = contextMap[context];
@@ -409,19 +423,26 @@ function checkRulePromise(xmlDoc, originalContext, assertionsAndExtensions, opti
409
423
 
410
424
  // Extract values from external document and modify test if a document call is made
411
425
  let originalTest = test;
426
+ let simplifiedTest = null;
412
427
  try {
413
428
  test = includeExternalDocument(test, resourceDir);
414
429
  }
415
430
  catch (err) {
416
- return { ignored: true, errorMessage: err.message };
417
- }
418
-
419
- let simplifiedTest = null;
431
+ failedAssertions.push({
432
+ type: level,
433
+ assertionId: id,
434
+ test: originalTest,
435
+ simplifiedTest: simplifiedTest,
436
+ description: description,
437
+ results: { ignored: true, errorMessage: err.message }
438
+ });
439
+ continue;
440
+ }
420
441
  if (originalTest !== test) {
421
442
  simplifiedTest = test;
422
443
  }
423
444
  if (level === 'error' || includeWarnings) {
424
- results.push({
445
+ failedAssertions.push({
425
446
  type: level,
426
447
  assertionId: id,
427
448
  test: originalTest,
@@ -440,12 +461,19 @@ function checkRulePromise(xmlDoc, originalContext, assertionsAndExtensions, opti
440
461
  if (!subAssertionsAndExtensions) {
441
462
  continue;
442
463
  }
443
- const newRuleObject = ruleAssertionMap[extensionRule];
464
+ const newRuleObject = ruleAssertionMap[extensionRule];
465
+ if (_get(newRuleObject, 'abstract')) {
466
+ continue;
467
+ }
444
468
  const newContext = newRuleObject.context;
445
- results = results.concat(checkRulePromise(xmlDoc, newContext, subAssertionsAndExtensions, options));
469
+ if (!newContext) {
470
+ continue;
471
+ }
472
+ const failedSubAssertions = checkRule(xmlDoc, newContext, subAssertionsAndExtensions, options);
473
+ failedAssertions.push(...failedSubAssertions);
446
474
  }
447
475
  }
448
- resolve (results);
476
+ resolve (failedAssertions);
449
477
  }
450
478
  catch (promiseError) {
451
479
  reject (new Error (`Promise Error: ${promiseError}`));