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

Escape newline characters in conditionalPanel expression #1820

Merged
merged 2 commits into from Aug 19, 2017

Conversation

wch
Copy link
Collaborator

@wch wch commented Aug 18, 2017

This fixes #1818.

Test app:

shinyApp(
  fluidPage(
    selectInput("select", "Select",
      c(First = "first", Second = "second")
    ),
    conditionalPanel(
      condition = "input.select ==
                   'second'",
      "This should be displayed only when 'Second' is selected."
    )
  ),
  function(input, output) { }
)

@jcheng5 jcheng5 merged commit ebd47aa into master Aug 19, 2017
@jcheng5 jcheng5 deleted the wch-fix-conditionalpanel branch August 19, 2017 00:49
@jcheng5
Copy link
Member

jcheng5 commented Aug 19, 2017

@wch Can you imagine any of these other escape sequences being needed to avoid these problems? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Using_special_characters_in_strings

@wch
Copy link
Collaborator Author

wch commented Aug 21, 2017

@jcheng5 I think there needs to be a couple more characters added to the escaping, namely \r and \b. Here's an example:

# This string contains the weird characters listed at
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Using_special_characters_in_strings
# including one Unicode character.
var expr =  '\0\b\f\n\t\r\v\'"\\\u5434';

var expr_escaped = expr
    .replace(/[\\"']/g, '\\$&')
    .replace(/\u0000/g, '\\0')
    .replace(/\n/g, '\\n')
    .replace(/\r/g, '\\r')
    // \b has a special meaning; need [\b] to match backspace char.
    .replace(/[\b]/g, '\\b');

eval(`"${expr_escaped}"`);

Without the added substitutions for \r and \b, the eval() gives an error. I can implement this if it looks good to you.

@wch
Copy link
Collaborator Author

wch commented Aug 21, 2017

I've updated it in e74592a.

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.

conditionalPanel error when there is a newline in expression (was: breaking changes in 1.0.4?)
2 participants