@reality.eth/reality-eth-lib 3.4.24 → 3.4.25

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.
@@ -184,7 +184,7 @@ exports.secondsTodHms = function(sec) {
184
184
  return dDisplay + hDisplay + mDisplay + sDisplay;
185
185
  }
186
186
 
187
- exports.parseQuestionJSON = function(data, errors_to_title) {
187
+ exports.parseQuestionJSON = function(data, errors_to_title, vsprint_errors) {
188
188
 
189
189
  // Strip unicode null-terminated-string control characters if there are any.
190
190
  // These seem to be stripped already if we got data via The Graph, and only passed to us on RPC.
@@ -211,12 +211,18 @@ exports.parseQuestionJSON = function(data, errors_to_title) {
211
211
  question_json['errors']['invalid_precision'] = true;
212
212
  }
213
213
  }
214
+
215
+ if (vsprint_errors && vsprint_errors['suspicious_extra_data']) {
216
+ if (!question_json['errors']) question_json['errors'] = {};
217
+ question_json['errors']['suspicious_extra_data'] = true;
218
+ }
219
+
214
220
  // If errors_to_title is specified, we add any error message to the title to make sure we don't lose it
215
221
  if (errors_to_title) {
216
222
  if ('errors' in question_json) {
217
223
  const prependers = {
218
224
  'invalid_precision': 'Invalid date format',
219
- 'too_many_outcomes': 'Too many outcomes'
225
+ 'too_many_outcomes': 'Too many outcomes',
220
226
  }
221
227
  for (const e in question_json['errors']) {
222
228
  if (e in prependers) {
@@ -263,7 +269,8 @@ exports.parseQuestionJSON = function(data, errors_to_title) {
263
269
  const prependers = {
264
270
  'invalid_format': 'Invalid format',
265
271
  'unsafe_markdown': 'Unsafe markdown',
266
- 'markdown_parse_failed': 'Bad markdown parse'
272
+ 'markdown_parse_failed': 'Bad markdown parse',
273
+ 'suspicious_extra_data': 'Suspicious Extra Data',
267
274
  }
268
275
  for (const e in question_json['errors']) {
269
276
  if (e in prependers) {
@@ -279,11 +286,22 @@ exports.parseQuestionJSON = function(data, errors_to_title) {
279
286
 
280
287
  exports.populatedJSONForTemplate = function(template, question, errors_to_title) {
281
288
  var qbits = question.split(module.exports.delimiter());
289
+ var interpolated = vsprintf(template, qbits);
290
+
291
+ var vsprint_errors = null;
292
+ if (question != '') {
293
+ var tweak_question = question + 'x';
294
+ var qbits2 = tweak_question.split(module.exports.delimiter());
295
+ var interpolated2 = vsprintf(template, qbits2);
296
+ if (interpolated == interpolated2) {
297
+ // console.log('suspicious_extra_data: ', question, template);
298
+ vsprint_errors = {'suspicious_extra_data': true};
299
+ }
300
+ }
282
301
  //console.log('pp', template);
283
302
  //console.log('qbits', qbits);
284
- var interpolated = vsprintf(template, qbits);
285
303
  //console.log('resulting template', interpolated);
286
- return module.exports.parseQuestionJSON(interpolated, errors_to_title);
304
+ return module.exports.parseQuestionJSON(interpolated, errors_to_title, vsprint_errors);
287
305
  }
288
306
 
289
307
  // Encode text, assuming the template has placeholders in the order specified in the params.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reality.eth/reality-eth-lib",
3
- "version": "3.4.24",
3
+ "version": "3.4.25",
4
4
  "description": "Tools for handling questions in the reality.eth fact verification platform",
5
5
  "scripts": {
6
6
  "test": "env TZ='Asia/Kabul' mocha ./test"
@@ -39,5 +39,5 @@
39
39
  "url": "https://github.com/RealityETH/monorepo/issues"
40
40
  },
41
41
  "homepage": "https://reality.eth.link",
42
- "gitHead": "65e11c3b5340b04c2d8243f7978a422f477c6354"
42
+ "gitHead": "8f89b31904d7c897a6e63fe9652c303a93d42ef0"
43
43
  }
@@ -27,7 +27,19 @@ describe('Default template types', function() {
27
27
  expect(q.type).to.equal(t);
28
28
  }
29
29
  });
30
-
30
+ it('marks the question if it has extra unused data', function() {
31
+ const outcomes = ["oink", "oink2"];
32
+ for (var i=0; i<option_types.length; i++) {
33
+ var t = option_types[i];
34
+ var qtext = rc_question.encodeText(t, 'oink', outcomes, 'my-category', 'en_US');
35
+ var q = rc_question.populatedJSONForTemplate(rc_template.defaultTemplateForType(t), qtext);
36
+ var qtext1 = rc_question.populatedJSONForTemplate(rc_template.defaultTemplateForType(t), qtext, true);
37
+ var qtext2 = qtext + '\u241f' + 'hey hey';
38
+ var q2 = rc_question.populatedJSONForTemplate(rc_template.defaultTemplateForType(t), qtext2, true);
39
+ expect(q.type).to.equal(t);
40
+ expect(JSON.stringify(q)).not.to.equal(JSON.stringify(q2));
41
+ }
42
+ });
31
43
  });
32
44
 
33
45
  describe('Answer formatting', function() {