Skip to content

Commit

Permalink
Fix unicode in object accesses, eg c["\u00FC"]=42 (fix #2429)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Nov 17, 2023
1 parent 08b6c14 commit 666b040
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Graphics: wrapString will now wrap lines on comma, dot, dash, and between images
Graphics: Improve PBF font loading to handle v3, plus Espruino extension to handle >10k glyphs in one file
Graphics: Graphics.stringMetrics now returns 'unknownChars' to indicate if a font can't render a character in the String
Fix unicode in object accesses, eg c["\u00FC"]=42 (fix #2429)

2v19 : Fix Object.values/entries for numeric keys after 2v18 regression (fix #2375)
nRF52: for SD>5 use static buffers for advertising and scan response data (#2367)
Expand Down
6 changes: 3 additions & 3 deletions src/jsvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ JsVar *jsvMakeIntoVariableName(JsVar *var, JsVar *valueOrZero) {
JsVar* ext = jsvNewWithFlags(JSV_STRING_EXT_0);
if (ext) {
jsvSetCharactersInVar(ext, (size_t)index);
jsvSetLastChild(last, jsvGetRef(ext));
jsvSetLastChild(last, jsvGetRef(ext)); // no ref for stringext
jsvUnLock(ext);
} // TODO else?
}
Expand Down Expand Up @@ -2783,10 +2783,10 @@ JsVar *jsvCopy(JsVar *src, bool copyChildren) {
} else {
JsVar *childCopy = jsvCopy(child, true);
if (childCopy) {// could be out of memory
jsvSetLastChild(dstChild, jsvGetRef(childCopy)); // no ref for stringext
jsvSetLastChild(dstChild, jsvGetRef(jsvRef(childCopy)));
jsvUnLock(childCopy);
}
jsvUnLock2(src, dstChild);
jsvUnLock3(src, dstChild, child);
return dst;
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/test_UTF8_fieldname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// https://github.com/espruino/Espruino/issues/2429
// there were already some changes in https://github.com/espruino/Espruino/commit/dde4d3a5ca52782fbe7cefacb18d52d9655b485a

const s = "\u00FC";
const o = {};
const o2 = {"\u00FC":42}; // this one was ok after above changes

//
print("==================== O2");
trace(o2); // ok
print("==================== O");
o[s] = 42;
trace(o); // not ok

// o an o2 were different before

result = o["\u00FC"]==42;

0 comments on commit 666b040

Please sign in to comment.