mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-07 03:00:20 -04:00
Add better error messages for errors parsing and evaluating JS code (#1727)
* Add better error messages for errors parsing and evaluating JS code * Grunt
This commit is contained in:
2
NEWS.md
2
NEWS.md
@@ -11,6 +11,8 @@ shiny 1.0.3.9000
|
||||
|
||||
Addressed [#1501](https://github.com/rstudio/shiny/issues/1501): The `fileInput` control now retains uploaded file extensions on the server. This fixes [readxl](https://github.com/tidyverse/readxl)'s `readxl::read_excel` and other functions that must recognize a file's extension in order to work. ([#1706](https://github.com/rstudio/shiny/pull/1706))
|
||||
|
||||
For `conditionalPanel`s, Shiny now gives more informative messages if there are errors evaluating or parsing the JavaScript conditional expression. ([#1727](https://github.com/rstudio/shiny/pull/1727))
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fixed [#1701](https://github.com/rstudio/shiny/issues/1701): There was a partial argument match in the `generateOptions` function. ([#1702](https://github.com/rstudio/shiny/pull/1702))
|
||||
|
||||
@@ -175,7 +175,14 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
|
||||
// "with" on the argument value, and return the result.
|
||||
function scopeExprToFunc(expr) {
|
||||
/*jshint evil: true */
|
||||
var func = new Function("with (this) {return (" + expr + ");}");
|
||||
var expr_escaped = expr.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
|
||||
try {
|
||||
var func = new Function('with (this) {\n try {\n return (' + expr + ');\n } catch (e) {\n console.error(\'Error evaluating expression: ' + expr_escaped + '\');\n throw e;\n }\n }');
|
||||
} catch (e) {
|
||||
console.error("Error parsing expression: " + expr);
|
||||
throw e;
|
||||
}
|
||||
|
||||
return function (scope) {
|
||||
return func.call(scope);
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
8
inst/www/shared/shiny.min.js
vendored
8
inst/www/shared/shiny.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -161,7 +161,24 @@ function pixelRatio() {
|
||||
// "with" on the argument value, and return the result.
|
||||
function scopeExprToFunc(expr) {
|
||||
/*jshint evil: true */
|
||||
var func = new Function("with (this) {return (" + expr + ");}");
|
||||
var expr_escaped = expr.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
|
||||
try {
|
||||
var func = new Function(
|
||||
`with (this) {
|
||||
try {
|
||||
return (${expr});
|
||||
} catch (e) {
|
||||
console.error('Error evaluating expression: ${expr_escaped}');
|
||||
throw e;
|
||||
}
|
||||
}`
|
||||
);
|
||||
} catch (e) {
|
||||
console.error("Error parsing expression: " + expr);
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
return function(scope) {
|
||||
return func.call(scope);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user