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

Close parenthesis fix #580

Merged
merged 5 commits into from
Apr 19, 2019
Merged

Close parenthesis fix #580

merged 5 commits into from
Apr 19, 2019

Conversation

vibhorgupta-gh
Copy link

@vibhorgupta-gh vibhorgupta-gh commented Dec 31, 2018

Fixes #459

  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts
  • PR is descriptively titled
  • ask @publiclab/reviewers for help, in a comment below

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@vibhorgupta-gh
Copy link
Author

screen shot 2018-12-31 at 1 37 16 pm

@jywarren there was a slight tweak in the regex, the end braces now appear in the options. Checked against this:

http://localhost:3000/examples/#steps=dynamic{red:map(r%2C0%2C255%2C0%2C128)|green:g|blue:b|monochrome%20(fallback):r%20%2B%20g%20%2B%20b}

@tech4GT please review :)

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Dec 31, 2018

@VibhorCodecianGupta the paranthesis "{ }" don't need to be escaped "\{" in regex.

@vibhorgupta-gh
Copy link
Author

@harshkhandeparkar that was already in place, I made changes to the closing braces only. Should I remove the ^ from ^\{ ?

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Dec 31, 2018

^ means the start of line. If we remove that, the pattern will still work as it only matches the first appearance but it is used for security. \ before the { is not needed as { matches itself literally in regex. But if its is used like {2} then it is a quantifier.

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Dec 31, 2018

I actually didn't understange your change. How can } be at the start and also end of string in /^\}$/ ? Doesn't it mean that it only matches a single character string?

@harshkhandeparkar
Copy link
Member

By the way, what settingValue can have a { at the start?

@vibhorgupta-gh
Copy link
Author

@harshkhandeparkar I tested out some possibilities, and it turns out that using the replace statement is not really required. The substring extracted already has () which are also necessary for the function in Dynamic module to run. The .replace functions can be done away with, considering we need the brackets for the function to run, like so map(r,0,255,0,128). Extracting the relevant substring and then decoding it should do the job.
Am I missing something here?

@harshkhandeparkar
Copy link
Member

Ya exactly, I felt the same way which is why I asked you the question. The replace might be redundant as it never finds a match but there may be other functions which have double parenthesis. We have to confirm this with @tech4GT or @jywarren.

@harshkhandeparkar
Copy link
Member

Maybe replacing { } is important but not ( ).

@vibhorgupta-gh
Copy link
Author

@harshkhandeparkar cool then. For now I'll update the pr with working commits, and proceed as mentors guide

@vibhorgupta-gh
Copy link
Author

@jywarren @tech4GT please advise

@jywarren
Copy link
Member

jywarren commented Jan 4, 2019

Hmm, ok -- maybe we need to take a step back and:

  1. write a test that demonstrates the original function of these replace methods (in positive and negative forms)
  2. write a test which demonstrates the bug I found in Close-parentheses in Dynamic module input get lost when sourced from URL #459

That'll ensure we know why it was originally created and we won't break the original purpose while fixing the new bug.

I looked at the blame:

https://github.com/publiclab/image-sequencer/blame/master/src/ImageSequencer.js#L308-L309

It led me back to #313

that made it possible to use {} as well as () to add parameters to a string formatted sequence. but original () code is here:

#279

I believe the original is attempting to make it possible to use {} to delimit parameters in string format, especially when passing a function in a parameter, as we are doing with map(). So maybe the original test needed is to pass in a string with a function as a parameter like map(), and confirm that the instantiated step has a complete but not malformed function -- that it preserved the () properly when adding the steps from the original string.

Then we can debug what happens here. How does that sound?

@publiclab publiclab deleted a comment from codecov bot Apr 17, 2019
@codecov
Copy link

codecov bot commented Apr 17, 2019

Codecov Report

Merging #580 into main will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #580   +/-   ##
=======================================
  Coverage   37.04%   37.04%           
=======================================
  Files         100      100           
  Lines        1857     1857           
  Branches      291      291           
=======================================
  Hits          688      688           
  Misses       1169     1169
Impacted Files Coverage Δ
src/Strings.js 18.07% <0%> (ø) ⬆️

@vibhorgupta-gh
Copy link
Author

vibhorgupta-gh commented Apr 17, 2019

@jywarren after looking at the aforementioned issues, and logging some outputs, this is what is happening:

Screen Shot 2019-04-17 at 9 36 12 PM

As can be seen, in favour of supporting #306 , the parenthesis was also expected to be removed from the string passing the steps and options. That works fine, except for the map() function which requires both the braces and parenthesis and hence the ending ) gets omitted along with }, which is undesirable. For now, the latest commit removes the replace function that removes the ending ) to support the map function, like so:

Screen Shot 2019-04-17 at 9 35 34 PM

This solution, however, completely depends on whether we still want IS to support the old syntax of using () instead of {}. In that case, I'll have to come up with some other logic.

@jywarren
Copy link
Member

jywarren commented Apr 17, 2019 via email

@vibhorgupta-gh
Copy link
Author

I guess we could drop the () then, and update the docs accordingly, explicitly mentioning that the said syntax is deprecated. Is it being used extensively in some other library leveraging IS? If not, this shouldn't be too much of a problem.
A more sophisticated parser as in? Didn't quite get you. I think the current one uses regex as well and does pretty well

@jywarren
Copy link
Member

Let's drop the (); I don't think any other apps are using it because it was from very early on. Thanks!!!

@jywarren
Copy link
Member

Nevermind about the parser... I think there's a way to "find matching parentheses" working from the outside in, but I really think it's not worth it even if it is possible. Thanks a lot!

@vibhorgupta-gh
Copy link
Author

vibhorgupta-gh commented Apr 18, 2019

@jywarren in that case, I think this is good to go. I'll just fix the conflicts then, and update the docs?

@jywarren
Copy link
Member

Great!!!

@vibhorgupta-gh
Copy link
Author

@jywarren can we make this a part of the next bump as well?

@jywarren
Copy link
Member

Merging this now! We'll try to pick it up in v3.3.2. Thanks!

@jywarren jywarren merged commit df09cf6 into publiclab:main Apr 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Close-parentheses in Dynamic module input get lost when sourced from URL
3 participants