From fb446c9bff6973610fa21db951a03c2ee270df19 Mon Sep 17 00:00:00 2001 From: hlomzik Date: Tue, 23 Jan 2024 15:34:27 +0000 Subject: [PATCH] fix: LEAP-580: Display non-string values in Text (#1675) * Fix: LEAP-580: Display non-string values in Text During recent incident fix we missed conversion to string for Text tag's `value` param. * Fix deprecated `substr` to `slice` in `parseValue` * Add cypress test for non-string values --------- Co-authored-by: hlomzik --- src/tags/object/RichText/model.js | 2 +- src/utils/data.js | 4 +- tests/functional/specs/object_tags/text.cy.ts | 37 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/functional/specs/object_tags/text.cy.ts diff --git a/src/tags/object/RichText/model.js b/src/tags/object/RichText/model.js index 698b575f3..ed05eb17d 100644 --- a/src/tags/object/RichText/model.js +++ b/src/tags/object/RichText/model.js @@ -222,7 +222,7 @@ const Model = types // nodes count better be the same, so replace them with stubs // we should not sanitize text tasks because we already have htmlEscape in view.js if (isFF(FF_SAFE_TEXT) && self.type === 'text') { - self._value = val; + self._value = String(val); } else { self._value = sanitizeHtml(String(val)); } diff --git a/src/utils/data.js b/src/utils/data.js index 82d4dab8f..edf0f63b9 100644 --- a/src/utils/data.js +++ b/src/utils/data.js @@ -16,10 +16,10 @@ export const parseValue = (value, task) => { // value can refer to structures, not only texts, so just replace wouldn't be enough if (value.match(reVar)?.[0] === value) { - return get(task, value.substr(1)) ?? ''; + return get(task, value.slice(1)) ?? ''; } - return value.replace(reVar, (v) => get(task, v.substr(1) ?? '')); + return value.replace(reVar, (v) => get(task, v.slice(1) ?? '')); }; /** diff --git a/tests/functional/specs/object_tags/text.cy.ts b/tests/functional/specs/object_tags/text.cy.ts new file mode 100644 index 000000000..f34b13b8f --- /dev/null +++ b/tests/functional/specs/object_tags/text.cy.ts @@ -0,0 +1,37 @@ +import { LabelStudio } from '@heartexlabs/ls-test/helpers/LSF'; + +describe(' tag', () => { + it('Display non-string values', () => { + const config = ` + +
String — usual case
+ +
Float number
+ +
Boolean
+ +
Array
+ +
+ + `; + + const data = { + string: 'Simple text', + number: 123.45, + bool: false, + array: [1, 2, 3], + }; + + LabelStudio.params() + .config(config) + .data(data) + .withResult([]) + .init(); + + cy.get('.lsf-object').contains('Simple text').should('be.visible'); + cy.get('.lsf-object').contains('123.45').should('be.visible'); + cy.get('.lsf-object').contains('false').should('be.visible'); + cy.get('.lsf-object').contains('1,2,3').should('be.visible'); + }); +});