Skip to content

Commit 0927778

Browse files
committed
html parse fix
1 parent a726b92 commit 0927778

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

tryhackme/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
__version__ = "1.2.6"
2+
__version__ = "1.2.7"
33

44
from .errors import *
55
from .converters import *

tryhackme/question.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ def __init__(self, state, data):
99

1010
def _from_data(self, data):
1111
self.raw_question = data.get("question")
12-
self.question = utils.HTML_parse(self.raw_question)
12+
self.question = utils.HTML_parse(self.raw_question).strip()
1313
self.raw_hint = data.get("hint")
14-
self.hint = utils.HTML_parse(self.raw_hint)
14+
self.hint = utils.HTML_parse(self.raw_hint).strip()
1515
self.number = data.get("questionNo")
1616

1717
# * only when authenticated
1818
self.raw_description = data.get("answerDesc", "")
19-
self.description = utils.HTML_parse(self.raw_description)
19+
self.description = utils.HTML_parse(self.raw_description).strip()
2020
self.extra_points = data.get("extraPoints", None)
2121
self.correct = data.get("correct", False)
2222
self.attempts = data.get("attempts", 0)

tryhackme/room.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from .errors import NotImplemented
22
from .task import RoomTask
3-
3+
from . import utils
44
# ? writeups class
55

66
class Room:
7-
__slots__ = ("__weakref__", "_state", "_creators", "name", "id", "title", "description", "created", "published", "users", "type", "public", "difficulty", "freeToUse", "ctf", "tags", "ipType", "simpleRoom", "writeups", "locked", "comingSoon", "views", "certificate", "timeToComplete", "userCompleted", )
7+
__slots__ = ("__weakref__", "_state", "_creators", "name", "id", "raw_title", "title", "raw_description", "description", "created", "published", "users", "type", "public", "difficulty", "freeToUse", "ctf", "tags", "ipType", "simpleRoom", "writeups", "locked", "comingSoon", "views", "certificate", "timeToComplete", "userCompleted", )
88

99
def __init__(self, state, data):
1010
self._state = state
@@ -22,8 +22,10 @@ def __init__(self, state, data):
2222
def _from_data(self, data):
2323
self.name = data.get("roomCode")
2424
self.id = data.get("roomId")
25-
self.title = data.get("title")
26-
self.description = data.get("description")
25+
self.raw_title = data.get("title")
26+
self.title = utils.HTML_parse(self.raw_title).strip()
27+
self.raw_description = data.get("description")
28+
self.description = utils.HTML_parse(self.raw_description).strip()
2729
self.created = data.get("created")
2830
self.published = data.get("published")
2931
self.users = data.get("users")

tryhackme/task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class RoomTask:
6-
__slots__ = ("_state", "_questions", "raw_title", "raw_description", "description", "type", "number", "created", "deadline", "uploadId", )
6+
__slots__ = ("_state", "_questions", "raw_title", "title", "raw_description", "description", "type", "number", "created", "deadline", "uploadId", )
77

88
def __init__(self, state, data):
99
self._state = state
@@ -13,9 +13,9 @@ def __init__(self, state, data):
1313

1414
def _from_data(self, data):
1515
self.raw_title = data.get('taskTitle')
16-
self.title = utils.HTML_parse(self.raw_title, "*")
16+
self.title = utils.HTML_parse(self.raw_title, "*").strip()
1717
self.raw_description = data.get('taskDesc')
18-
self.description = utils.HTML_parse(self.raw_description)
18+
self.description = utils.HTML_parse(self.raw_description).strip()
1919
self.type = data.get('taskType')
2020
self.number = data.get('taskNo')
2121
self.created = data.get('taskCreated')

tryhackme/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def response_to_json_or_text(response):
1515
pass
1616
return text
1717

18-
_HTML_TAGS_ = re.compile("<[^<]*>")
18+
_HTML_TAGS_ = re.compile("<[^<]*?>")
1919
def HTML_parse(text, replace=""):
2020
text = text.replace("\n", "")
2121
text = html.unescape(text)

0 commit comments

Comments
 (0)