-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug caused by accidentally writing code with un-escaped special c…
…haracters
- Loading branch information
Showing
5 changed files
with
98 additions
and
19 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
inst/editor/src/ui-node-definitions/code_generation/printPrimative.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Primatives } from "../../r-parsing"; | ||
|
||
/** | ||
* Print a primative value to R or python code. | ||
* Handles special cases like special strings and booleans | ||
* @param val | ||
* @returns | ||
*/ | ||
export function printPrimative(val: Primatives): string { | ||
switch (typeof val) { | ||
case "string": { | ||
return safeStringPrint(val); | ||
} | ||
|
||
default: | ||
return String(val); | ||
} | ||
} | ||
|
||
/** | ||
* Escape special characters in a string for R or python code | ||
* @param str The string to escape | ||
* @returns The string with special characters like slashes and quotes escaped | ||
*/ | ||
export function safeStringPrint(str: string): string { | ||
// Right now we just use json stringify to escape special characters but in | ||
// the future this may not be enough so we abstract it to a function so we | ||
// don't have to change a million locations | ||
return JSON.stringify(str); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters