[No QA] Add sanitizeStringForJSONParse and use it in getMergeLogsAsJSON#14351
Conversation
|
@sobitneupane @amyevans One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
6cb62ff to
ce5e791
Compare
| */ | ||
| function sanitizeStringForJSONParse(inputString) { | ||
| if (!inputString || typeof inputString !== 'string') { | ||
| return ''; |
There was a problem hiding this comment.
NAB but maybe it's better to just throw an error rather than returning an empty string
Co-authored-by: Rory Abraham <47436092+roryabraham@users.noreply.github.com>
| * @param {String} inputString | ||
| * @returns {String} | ||
| */ | ||
| export default function (inputString) { |
There was a problem hiding this comment.
@roryabraham any idea what I'm doing wrong here? https://github.com/Expensify/App/actions/runs/3935291814/jobs/6730848329
There was a problem hiding this comment.
oh, that's annoying... Here's what I think is happening there:
src/libs/sanitizeStringForJSONParse.jsis written as an ES6 module ("native JavaScript module",import/export).- Normally CommonJS (CJS) modules ("Node.js modules",
require/module.exports) cannot understand ES6 modules. We can import ES6 modules in some cases (such as in the GitHub Actions) when the code importing that ES6 module is preprocessed by babel, ncc, or some other compile-time bundler. - Furthermore, newer versions of Node.js can understand ES6 modules if they're in a file ending with
.mjsinstead of just.js - The test you're looking at executes JavaScript via a Node.JS wrapper script here (note the file ending in MJS allows Node to understand ES6 modules, but only for that file)
- Recall that when JavaScript files are imported, they are immediately evaluated. So when the
.mjsfile tries to import the.jsfile, it defaults back to reading in CJS and then barfs when it sees theexportkeyword
There was a problem hiding this comment.
This is always so confusing. I'm not sure the best way to make a javascript library reusable between ES6 and CJS, but I know there's a way to do it.
There was a problem hiding this comment.
I think for now the path-of-least resistance to fix this would be to:
- Move
src/libs/sanitizeStringForJSONParse.jsto.github/libs/sanitizeStringForJSONParse.js - Convert
.github/libs/sanitizeStringForJSONParse.jsto a CJS module (replaceexport default ...withmodule.exports = ...
There was a problem hiding this comment.
Deprecating .github/libs and providing a cleaner way to share JS code between the main application and the GitHub Actions could be a good future project.
There was a problem hiding this comment.
I think @roryabraham approach sounds great at the moment! I think the github actions in general would deserve some clean up once we get a bit more time
mountiny
left a comment
There was a problem hiding this comment.
Thank @yuwenmemon for doing this!
| * @param {String} inputString | ||
| * @returns {String} | ||
| */ | ||
| export default function (inputString) { |
There was a problem hiding this comment.
I think @roryabraham approach sounds great at the moment! I think the github actions in general would deserve some clean up once we get a bit more time
| */ | ||
| function sanitizeStringForJSONParse(inputString) { | ||
| if (!inputString || typeof inputString !== 'string') { | ||
| return ''; |
5099e4e to
7ea43c3
Compare
7ea43c3 to
8dd8b30
Compare
|
Thanks folks! Updated! |
Reviewer Checklist
Screenshots/VideosNo screenshots for this GitHub Actions change. WebMobile Web - ChromeMobile Web - SafariDesktopiOSAndroid |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
Performance Comparison Report 📊Significant Changes To DurationThere are no entries Meaningless Changes To DurationShow entries
Show details
|
|
🚀 Deployed to staging by @roryabraham in version: 1.2.56-0 🚀
|
|
@yuwenmemon @roryabraham Can you QA this internally? |
|
Ah this [No QA] I guess. Feel free to check it off! |
|
🚀 Deployed to production by https://github.com/AndrewGable in version: 1.2.56-0 🚀
|
@roryabraham please review
cc @francoisl @chiragsalian @AndrewGable
Details
Fix discussed here: https://expensify.slack.com/archives/C07J32337/p1670871959612579
Create a function to make strings safe for
getMergeLogsAsJSON'sJSON.parsecall. Add unit test guardrails around it so we can make it more robust looking forward into the future.Fixed Issues
$ #13649
Tests/QA
Offline tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.Screenshots/Videos
Web
-N/A
Mobile Web - Chrome
-N/A
Mobile Web - Safari
-N/A
Desktop
-N/A
iOS
-N/A
Android
-N/A