Skip to content

Commit b5576c2

Browse files
committed
fix string parser
1 parent 2405ddd commit b5576c2

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

docs/changelog.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@
1010
- ext.commands
1111
- Changes
1212
- Added which alias failed to load in the error raised by :func:`~twitchio.ext.commands.Context.add_command`
13+
14+
- Bug fixes
15+
- fix string parser not properly parsing specific quoted strings
1316

1417
- ext.eventsub
1518
- Additions
1619
- Added :method:`Twitchio.ext.eventsub.EventSubClient.subscribe_channel_unban_request_create <EventSubClient.subscribe_channel_unban_request_create>` /
1720
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_channel_unban_request_create <EventSubWSClient.subscribe_channel_unban_request_create>`
1821
- Added :method:`Twitchio.ext.eventsub.EventSubClient.subscribe_channel_unban_request_resolve <EventSubClient.subscribe_channel_unban_request_resolve>` /
1922
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_channel_unban_request_resolve <EventSubWSClient.subscribe_channel_unban_request_resolve>`
23+
- Added :method:`Twitchio.ext.eventsub.EventSubClient.subscribe_automod_terms_update <EventSubClient.subscribe_automod_terms_update>` /
24+
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_automod_terms_update <EventSubClient.subscribe_automod_terms_update>`
25+
- Added :method:`Twitchio.ext.eventsub.EventSubClient.subscribe_automod_settings_update <EventSubClient.subscribe_automod_settings_update>` /
26+
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_automod_settings_update <EventSubClient.subscribe_automod_settings_update>`
27+
- Added :method:`Twitchio.ext.eventsub.EventSubClient.subscribe_automod_message_update <EventSubClient.subscribe_automod_message_update>` /
28+
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_automod_message_update <EventSubClient.subscribe_automod_message_update>`
29+
- Added :method:`Twitchio.ext.eventsub.EventSubClient.subscribe_automod_message_hold <EventSubClient.subscribe_automod_message_hold>` /
30+
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_automod_message_hold <EventSubClient.subscribe_automod_message_hold>`
31+
- Added all accompanying models for those endpoints.
2032
- ext.sounds
2133
- Additions
2234
- Added TinyTag as a dependency to support retrieving audio metadata using TinyTag in `ext.sounds.__init__.py`.

twitchio/ext/commands/stringparser.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,31 @@ def __init__(self):
3737
self.ignore = False
3838

3939
def process_string(self, msg: str) -> Dict[int, str]:
40-
while True:
41-
try:
42-
loc = msg[self.count]
43-
except IndexError:
44-
self.eof = self.count
45-
word = msg[self.start : self.eof]
46-
if not word:
47-
break
48-
self.words[self.index] = msg[self.start : self.eof]
49-
break
50-
51-
if loc.isspace() and not self.ignore:
52-
self.words[self.index] = msg[self.start : self.count].replace(" ", "", 1)
40+
while self.count < len(msg):
41+
loc = msg[self.count]
42+
43+
if loc == '"' and not self.ignore:
44+
self.ignore = True
45+
self.start = self.count + 1
46+
47+
elif loc == '"' and self.ignore:
48+
self.words[self.index] = msg[self.start : self.count]
5349
self.index += 1
50+
self.ignore = False
5451
self.start = self.count + 1
5552

56-
elif loc == '"':
57-
if not self.ignore:
58-
if self.start == self.count: # only tokenize if they're a new word
59-
self.start = self.count + 1
60-
self.ignore = True
61-
else:
53+
elif loc.isspace() and not self.ignore:
54+
if self.start != self.count:
6255
self.words[self.index] = msg[self.start : self.count]
6356
self.index += 1
64-
self.count += 1
65-
self.start = self.count
66-
self.ignore = False
57+
58+
self.start = self.count + 1
6759

6860
self.count += 1
61+
62+
if self.start < len(msg) and not self.ignore:
63+
self.words[self.index] = msg[self.start : len(msg)].strip()
64+
6965
return self.words
7066

7167
def copy(self) -> StringParser:

0 commit comments

Comments
 (0)