Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check _config.escapeFormulae is true #1025

Merged
merged 2 commits into from
Oct 9, 2023

Conversation

sp94
Copy link
Contributor

@sp94 sp94 commented Oct 9, 2023

When parsing the config with a boolean value of escapeFormulae, the presence of the escapeFormulae key is checked but the value itself is not checked.

This means that _config = {escapeFormulae: false} behaves the same as _config = {escapeFormulae: true}.

Codesandbox example

import "./styles.css";
import Papa from "papaparse";

export default function App() {
  const data = [
    ["a", "b"],
    [1, "=1+2"]
  ];
  const emptyConfigResult = Papa.unparse(data, {});
  const escapeFormulaeFalseResult = Papa.unparse(data, {
    escapeFormulae: false
  });
  const escapeFormulaeTrueResult = Papa.unparse(data, { escapeFormulae: true });

  return (
    <div className="App">
      <h3>Empty config</h3>
      <pre>{emptyConfigResult}</pre>
      <h3>escapeFormulae = false</h3>
      <pre>{escapeFormulaeFalseResult}</pre>
      <h3>escapeFormulae = true</h3>
      <pre>{escapeFormulaeTrueResult}</pre>
    </div>
  );
}

Result

Empty config

a,b
1,=1+2

escapeFormulae = false

a,b
1,"'=1+2"

escapeFormulae = true

a,b
1,"'=1+2"

This PR adds a check that escapeFormulae is truthy before using the default regex for escaping formulae.

@pokoli pokoli merged commit f1d10ee into mholt:master Oct 9, 2023
3 checks passed
@pokoli
Copy link
Collaborator

pokoli commented Oct 9, 2023

I've merged the fix. Thanks for the patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants