Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit cfb3986

Browse files
committed
validate: don't mix up info array and array containers
1 parent 081bec4 commit cfb3986

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/plot_api/validate.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,16 @@ function crawl(objIn, objOut, schema, list, base, path) {
163163
var valIn = objIn[k],
164164
valOut = objOut[k];
165165

166-
var nestedSchema = getNestedSchema(schema, k);
166+
var nestedSchema = getNestedSchema(schema, k),
167+
isInfoArray = (nestedSchema || {}).valType === 'info_array';
167168

168169
if(!isInSchema(schema, k)) {
169170
list.push(format('schema', base, p));
170171
}
171172
else if(isPlainObject(valIn) && isPlainObject(valOut)) {
172173
crawl(valIn, valOut, nestedSchema, list, base, p);
173174
}
174-
else if(nestedSchema.items && isArray(valIn)) {
175+
else if(nestedSchema.items && !isInfoArray && isArray(valIn)) {
175176
var itemName = k.substr(0, k.length - 1);
176177

177178
for(var j = 0; j < valIn.length; j++) {
@@ -186,7 +187,7 @@ function crawl(objIn, objOut, schema, list, base, path) {
186187
else if(!isPlainObject(valIn) && isPlainObject(valOut)) {
187188
list.push(format('object', base, p, valIn));
188189
}
189-
else if(!isArray(valIn) && isArray(valOut) && nestedSchema.valType !== 'info_array') {
190+
else if(!isArray(valIn) && isArray(valOut) && !isInfoArray) {
190191
list.push(format('array', base, p, valIn));
191192
}
192193
else if(!(k in objOut)) {

test/jasmine/tests/validate_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ describe('Plotly.validate', function() {
138138
);
139139
});
140140

141+
it('should work with info arrays', function() {
142+
var out = Plotly.validate([{
143+
y: [1, 2, 2]
144+
}], {
145+
xaxis: { range: [0, 10] },
146+
yaxis: { range: 'not-gonna-work' },
147+
});
148+
149+
expect(out.length).toEqual(1);
150+
assertErrorContent(
151+
out[0], 'value', 'layout', null, ['yaxis', 'range'], 'yaxis.range',
152+
'In layout, key yaxis.range is set to an invalid value (not-gonna-work)'
153+
);
154+
});
155+
141156
it('should work with isLinkedToArray attributes', function() {
142157
var out = Plotly.validate([], {
143158
annotations: [{

0 commit comments

Comments
 (0)