Skip to content

Commit 791e99a

Browse files
committed
Fix jsvStringIteratorGetCharOrMinusOne for zero-length strings
Allow tab-completion straight after '.'
1 parent d58372f commit 791e99a

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Add shortcut for quick execution of common call types
33
Fix BBC micro:bit save() regression from 1v86
44
Fix 'lock overflow' when calling methods with 'this' bound (fix #870, fix #885)
5+
Fix jsvStringIteratorGetCharOrMinusOne for zero-length strings
6+
Allow tab-completion straight after '.'
57

68
1v86 : Compile Telnet server into linux by default, Add '--telnet' command-line option to enable it
79
Fix lock 'leak' in Telnet when Telnet is turned off

src/jsinteractive.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,22 +1187,26 @@ void jsiTabComplete() {
11871187
}
11881188
jslKill();
11891189
jslSetLex(oldLex);
1190-
if (!data.partial) {
1191-
jsvUnLock(object);
1190+
if (!object && !data.partial) {
11921191
return;
11931192
}
1194-
data.partialLen = jsvGetStringLength(data.partial);
1195-
size_t actualPartialLen = inputCursorPos + 1 - partialStart;
1196-
if (actualPartialLen > data.partialLen) {
1197-
// we had a token but were past the end of it when asked
1198-
// to autocomplete ---> no token
1199-
jsvUnLock(data.partial);
1200-
return;
1201-
} else if (actualPartialLen < data.partialLen) {
1202-
JsVar *v = jsvNewFromStringVar(data.partial, 0, actualPartialLen);
1203-
jsvUnLock(data.partial);
1204-
data.partial = v;
1205-
data.partialLen = actualPartialLen;
1193+
if (data.partial) {
1194+
data.partialLen = jsvGetStringLength(data.partial);
1195+
size_t actualPartialLen = inputCursorPos + 1 - partialStart;
1196+
if (actualPartialLen > data.partialLen) {
1197+
// we had a token but were past the end of it when asked
1198+
// to autocomplete ---> no token
1199+
jsvUnLock(data.partial);
1200+
return;
1201+
} else if (actualPartialLen < data.partialLen) {
1202+
JsVar *v = jsvNewFromStringVar(data.partial, 0, actualPartialLen);
1203+
jsvUnLock(data.partial);
1204+
data.partial = v;
1205+
data.partialLen = actualPartialLen;
1206+
}
1207+
} else {
1208+
data.partial = jsvNewFromEmptyString();
1209+
data.partialLen = 0;
12061210
}
12071211

12081212
// If we had the name of an object here, try and look it up

src/jsvariterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static ALWAYS_INLINE char jsvStringIteratorGetChar(JsvStringIterator *it) {
5656

5757
/// Gets the current (>=0) character (or -1)
5858
static ALWAYS_INLINE int jsvStringIteratorGetCharOrMinusOne(JsvStringIterator *it) {
59-
if (!it->ptr) return -1;
59+
if (!it->ptr || it->charIdx>=it->charsInVar) return -1;
6060
return (int)(unsigned char)READ_FLASH_UINT8(&it->ptr[it->charIdx]);
6161
}
6262

0 commit comments

Comments
 (0)