Skip to content

Commit 27ae40c

Browse files
rashedmytPrabhakar Kumar
authored andcommitted
Updates kernel to force usage of builtin functions to avoid name clashes with user defined path functions.
fixes #47
1 parent 9aa5b1b commit 27ae40c

File tree

1 file changed

+9
-6
lines changed
  • src/jupyter_matlab_kernel/matlab/+jupyter

1 file changed

+9
-6
lines changed

src/jupyter_matlab_kernel/matlab/+jupyter/execute.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
function request = updateRequestFromVersion1(request, code)
8989
request.sectionBoundaries = [];
9090
request.startLine = 1;
91-
request.endLine = numel(splitlines(code));
91+
request.endLine = builtin('count', code, newline) + 1;
9292

9393
% Allow figures to be used across Notebook cells. Cleanup needs to be
9494
% done explicitly when the kernel shutsdown.
@@ -175,7 +175,7 @@
175175

176176
function result = processVariableString(output)
177177
indentation = '';
178-
useSingleLineDisplay = ~contains(output.value, sprintf(newline));
178+
useSingleLineDisplay = ~(builtin('contains', output.value, newline));
179179
if useSingleLineDisplay
180180
if ~isempty(output.header)
181181
indentation = sprintf(newline);
@@ -242,12 +242,15 @@
242242
result.content.text = text;
243243

244244
% Helper function for processing figure outputs.
245-
% base64Data will be "data:image/png;base64,<base64_value>"
245+
% base64Data will be 'data:image/png;base64,<base64_value>'
246246
function result = processFigure(base64Data)
247+
pattern = "data:(?<mimetype>.*);base64,(?<value>.*)";
248+
result = builtin('regexp', base64Data, pattern, 'names');
249+
assert(builtin('startsWith', result.mimetype, 'image'), 'Error in processFigure. ''mimetype'' is not an image');
250+
assert(~isempty(result.value), 'Error in processFigure. ''value'' is empty');
251+
result.mimetype = {result.mimetype};
252+
result.value = {result.value};
247253
result.type = 'execute_result';
248-
base64DataSplit = split(base64Data,";");
249-
result.mimetype = {extractAfter(base64DataSplit{1},5)};
250-
result.value = {extractAfter(base64DataSplit{2},7)};
251254

252255
% Helper function to notify browser page load finished
253256
function pageLoadCallback(~,~,idler)

0 commit comments

Comments
 (0)