protect config.js from attempting to use invalid theme name (which corrupted mermaid use until reset()) #2987
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This protects the use of invalid theme names the same way they are protected in MermaidAPI.js.
The situation that led to finding this bug was a mistyped:
%%{init: {"theme": "neutrl" }}%%
This led to the directive array getting corrupted with a
theme:'neutrl'
value, which in turn prevented all future use of the library entirely until reset() was called. (any attempt to call anything but reset() causes exception again)Calls to setConfig() or initialize() also failed because the code in config.js would exception out because the invalid theme name was being use to index into theme[] and causing an exception.
This change simply protects from the use of invalid theme names:
(please refer to changes for more context)
if (sumOfDirectives.theme) {
becomes:
if (sumOfDirectives.theme && theme[sumOfDirectives.theme]) {
(and for good measure, but not where exception was)
if (conf.theme) {
becomes
if (conf.theme && theme[conf.theme]) {
again this is identical to how MermaidAPI.js protects against using invalid theme names.