Skip to content

Commit

Permalink
fixed: falsely detects nested repeats for sibling repeats where one r…
Browse files Browse the repository at this point in the history
…epeat nodeName starts with the nodeName of another repeat,

OpenClinica/enketo-express-oc#260
  • Loading branch information
MartijnR committed Nov 7, 2019
1 parent e83e371 commit da785bc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

[Unreleased]
---------------------
##### Fixed
- Falsely detects nested repeats for sibling repeats where one repeat nodeName starts with the nodeName of another repeat.

[1.8.1] - 2019-11-06
---------------------
##### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![coverage-shield-badge-1](https://img.shields.io/badge/coverage-97.64%25-brightgreen.svg)
![coverage-shield-badge-1](https://img.shields.io/badge/coverage-97.65%25-brightgreen.svg)
[![npm version](https://badge.fury.io/js/enketo-validate.svg)](http://badge.fury.io/js/enketo-validate) [![Build Status](https://travis-ci.org/enketo/enketo-validate.svg?branch=master)](https://travis-ci.org/enketo/enketo-validate) [![Dependency Status](https://david-dm.org/enketo/enketo-validate/status.svg)](https://david-dm.org/enketo/enketo-validate) [![devDependency Status](https://david-dm.org/enketo/enketo-validate/dev-status.svg)](https://david-dm.org/enketo/enketo-validate?type=dev)

Enketo Validate
Expand Down
2 changes: 1 addition & 1 deletion src/xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class XForm {
this.repeats.reverse().forEach( repeat => {
const nodeset = repeat.getAttribute( 'nodeset' );
// This check will fail if relative nodesets are used (not supported in Enketo any more).
if ( repeatPaths.some( repeatPath => repeatPath.startsWith( nodeset ) ) ) {
if ( repeatPaths.some( repeatPath => repeatPath.startsWith( nodeset + '/' ) ) ) {
const name = nodeset.substring( nodeset.lastIndexOf( '/' ) + 1 );
warnings.push( `Repeat "${name}" contains a nested repeat. This not recommended.` );
}
Expand Down
21 changes: 21 additions & 0 deletions test/xform/nested-repeats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
</group>
</kids>
<gps/>
<repeat jr:template="">
<b/>
</repeat>
<repeat-confusion jr:template="">
<a/>
</repeat-confusion>
<orx:meta>
<orx:instanceID/>
</orx:meta>
Expand Down Expand Up @@ -77,5 +83,20 @@
</input>
</group>
</group>
<group ref="/data/repeat">
<repeat nodeset="/data/repeat">
<input ref="/data/repeat/a">
<label>a</label>
</input>
</repeat>
</group>
<!-- not a nested repeat, but in the past was identified as one -->
<group ref="/data/repeat-confusion">
<repeat nodeset="/data/repeat-confusion">
<input ref="/data/repeat-confusion/b">
<label>a</label>
</input>
</repeat>
</group>
</h:body>
</h:html>

0 comments on commit da785bc

Please sign in to comment.