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

[steps] [Issue 2261] Fix multiline text messages #359

Merged

Conversation

radoslawkrzemien
Copy link
Contributor

@radoslawkrzemien radoslawkrzemien commented Mar 8, 2024

Why

expo/eas-cli#2261
New line characters for messages dynamically generated in previous steps were incorrectly escaped, which resulted in incorrect formatting of the message received over Slack

How

Added a function that fixes incorrect escape characters when getting values from all inputs

Test Plan

Automated tests pass
Added more tests to cover multiline input as well as incorrectly escaped multiline input based on manual tests
Tested manually

Config
Screenshot 2024-03-08 at 13 23 17
Before After
Screenshot 2024-03-08 at 13 22 45 Screenshot 2024-03-08 at 13 22 53

Extracted the logic to a separate function and added tests for the case that came up during testing

See: https://linear.app/expo/issue/ENG-11196/create-custom-build-example-slacking-team-members
Copy link
Contributor

@sjchmiela sjchmiela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this live in the interpolateObject function you've been modifying recently?

@radoslawkrzemien
Copy link
Contributor Author

Possibly, I can look into that, but I'm not sure at which step exactly the \n character gets doubly escaped. Since this fix doesn't touch any other functionality I thought we could ship it so the user can use the function as he wants. I'll check the interpolation again

@radoslawkrzemien
Copy link
Contributor Author

Besides, I think this issue happened not only on interpolated message contents, so I'm not sure if changing interpolateObject would help, but I'll double check

@sjchmiela
Copy link
Contributor

I was thinking that maybe the same problem happens in other places, not only when sending a Slack message. If it does, it'd be great to make the fix "global".

@radoslawkrzemien
Copy link
Contributor Author

I can agree with that, will look more into it

Removed fixing escape characters from sendSlackMessage.ts to make it more global

See: https://linear.app/expo/issue/ENG-11196/create-custom-build-example-slacking-team-members
Added escape character fix to value getter in BuildStepInput.ts

See: expo/eas-cli#2261
Added tests for global fix for new line escape characters

See: expo/eas-cli#2261
@radoslawkrzemien radoslawkrzemien changed the title [eas-build] [Issue 2261] Fix multiline text messages [steps] [Issue 2261] Fix multiline text messages Mar 11, 2024
@radoslawkrzemien
Copy link
Contributor Author

@sjchmiela Made it global for all BuildStepInputs

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.54%. Comparing base (088c9a1) to head (edc9fd5).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #359      +/-   ##
==========================================
+ Coverage   91.45%   91.54%   +0.09%     
==========================================
  Files          22       22              
  Lines         994     1004      +10     
  Branches      210      213       +3     
==========================================
+ Hits          909      919      +10     
  Misses         85       85              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@szdziedzic szdziedzic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks reasonable, thanks!

input: BuildStepInputValueTypeWithRequired<T, R>
): BuildStepInputValueTypeWithRequired<T, R> {
if (typeof input === 'string') {
return input.replace(/\\n/g, '\n') as BuildStepInputValueTypeWithRequired<T, R>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about \\t? Is there a JS function, something more standard that unescapes this sort of thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I know of

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is decodeURI[Component] which could decode these. However, a bigger question is why do these strings contain \\n and not \n? Maybe we don't need to decode input, but instead we should fix output?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but atm I don't know if the problem is the earlier step setting the output, reading the outputs value, interpolating the input with other steps output, reading the interpolated input, or any other place.
I propose releasing this, since it actually fixes the problem that the user has and then digging deeper to look for the root cause

@radoslawkrzemien radoslawkrzemien merged commit b8e6954 into main Mar 12, 2024
6 checks passed
@radoslawkrzemien radoslawkrzemien deleted the @radoslawkrzemien/issue-2261-fix-multiline-text-messages branch March 12, 2024 09:31
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.

3 participants