Skip to content

Unwanted string slice when cell value starts with ' #617

Closed

Description

@rsify

To integrate HyperFormula with Handsontable properly, we need the formulas to be "semantically reversible" - the value that a user puts in, after whatever cell type tranformations, should be the same as the serialized value they get out that we'll display a cell editor for them.

The case with escaped formulas with ' seems not to meet that goal, consider this case:

  1. User sets cell contents to "'sum(2, 2)" (hf.setCellContents(address, "'=sum(2, 2)")).
  2. User wants to edit cell contents, the editor value we show them directly with hf.getCellSerialized will now be =sum(2, 2), with the leading ' omitted.
  3. User saves cell contents without any edits of their own, now hf.getCellValue returns 4 instead of the escaped formula.

See the snippet below.


import {HyperFormula} from 'hyperformula'

const hf = HyperFormula.buildFromArray([['']], {licenseKey: 'non-commercial-and-evaluation'})

const address = {
	sheet: 0,
	row: 0,
	col: 0
}

hf.setCellContents(address, "'=sum(2, 2)")

console.log(hf.getCellSerialized(address)) // "=sum(2, 2)", desired "'=sum(2, 2)"
console.log(hf.getCellValue(address)) // "=sum(2, 2)", desired "'=sum(2, 2)"

hf.setCellContents(address, hf.getCellSerialized(address))

console.log(hf.getCellValue(address)) // "4", desired "'=sum(2, 2)"

The problematic lines seem to be

return new CellContent.String(
content.startsWith('\'') ? content.slice(1) : content,
)


We'd be happy with always having the leading ' characters returned as we can easily trim them during presentation.


  • HyperFormula version: 0.4.0 & develop

Activity

  1. added
    Bug
    on Mar 29, 2021
  2. self-assigned this
    on Mar 29, 2021
  3. added
    Verified
    on Apr 8, 2021
  4. izulin commented on Apr 21, 2021

    @izulin
    Contributor

    closed with #619

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugVerified

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions