-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB but maybe it's better to just throw an error rather than returning an empty string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, that's annoying... Here's what I think is happening there:
src/libs/sanitizeStringForJSONParse.js
is 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
.mjs
instead 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
.mjs
file tries to import the.js
file, it defaults back to reading in CJS and then barfs when it sees theexport
keyword
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now the path-of-least resistance to fix this would be to:
- Move
src/libs/sanitizeStringForJSONParse.js
to.github/libs/sanitizeStringForJSONParse.js
- Convert
.github/libs/sanitizeStringForJSONParse.js
to a CJS module (replaceexport default ...
withmodule.exports = ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank @yuwenmemon for doing this!
* @param {String} inputString | ||
* @returns {String} | ||
*/ | ||
export default function (inputString) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
5099e4e
to
7ea43c3
Compare
7ea43c3
to
8dd8b30
Compare
Thanks folks! Updated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.parse
call. 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 Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component 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