GithubHelp home page GithubHelp logo

Globbing about slacktee HOT 7 CLOSED

coursehero avatar coursehero commented on July 17, 2024
Globbing

from slacktee.

Comments (7)

Chikashi-Kato avatar Chikashi-Kato commented on July 17, 2024

Thank you for checking the function get_ok_in_response(), @ky4k0b . I have tested it on my end and it seems working well.
Here is my test result:

$ get_ok_in_response '{"ok":true,"text":"a b c"}'
true
$ get_ok_in_response '{"text":"a b c","ok":true}'
true

# Testing the cases with awk used in the function
$ echo '{"text":"a b c","ok":true}' | awk 'match($0, /"ok":([^,}]+)/) {print substr($0, RSTART+5, RLENGTH-5)}'
true
$ echo '{"ok":true,"text":"a b c"}' | awk 'match($0, /"ok":([^,}]+)/) {print substr($0, RSTART+5, RLENGTH-5)}'
true

Seems like your test data doesn't have the opening " for text. Could you check if that is actually missing in the response of Slack API?

from slacktee.

ky4k0b avatar ky4k0b commented on July 17, 2024

@Chikashi-Kato
check how you pass variables into this function
if [[ $(get_ok_in_response $post_result) != "true" ]]; then
now consider this example:

manage:~# function get_ok_in_response() {
>     local response=$1
>     echo "$(echo "$response" | awk 'match($0, /"ok":([^,}]+)/) {print substr($0, RSTART+5, RLENGTH-5)}')"
> }
manage:~# ok='{"ok":true,"text":"a b c"}'
manage:~# not_ok='{"text":"a b c","ok":true}'
manage:~# get_ok_in_response $ok
true
manage:~# get_ok_in_response $not_ok

manage:~# get_ok_in_response "$not_ok"
true
manage:~#

from slacktee.

Chikashi-Kato avatar Chikashi-Kato commented on July 17, 2024

Ohhh, I see. Now I could reproduce the issue.
Sorry I didn't fully understand your explanation and also, I was using zsh instead of bash.
I agree with you. We should wrap $post_result with " for avoiding the unexpected issue caused by the change of the Slack API in future!

from slacktee.

Chikashi-Kato avatar Chikashi-Kato commented on July 17, 2024

@ky4k0b While I'm fixing the bug, could you explain why the function call doesn't work with $not_ok without wrapping of "? I tried to figure it out by myself but couldn't find the root cause of the behavior. 🤔

from slacktee.

ky4k0b avatar ky4k0b commented on July 17, 2024

it's all about empty strings, strings with spaces and strings with special symbols like *
without wrapping with " it runs like this:
get_ok_in_response $not_ok
vvv
get_ok_in_response {"text":"a b c","ok":true}
vvv
it takes {"text":"a as a first argument cause of space delimiter
more explanations and cool examples here: https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable

from slacktee.

Chikashi-Kato avatar Chikashi-Kato commented on July 17, 2024

Ah! Space delimiter!!! That makes a lot of sense! Thank you so much for your explanation and the link to the stack overflow page!!!

from slacktee.

Chikashi-Kato avatar Chikashi-Kato commented on July 17, 2024

Merged the fix into master. Thanks again for your report, @ky4k0b !

from slacktee.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.