Browse Source

fix: work Adele"s magic

master
Dominique Merle 2 years ago
parent
commit
2c1784d864
  1. 11
      addons/majority_judgment/MajorityJudgmentParticipant.gd
  2. 4
      addons/majority_judgment/MajorityJudgmentPoll.gd

11
addons/majority_judgment/MajorityJudgmentParticipant.gd

@ -17,14 +17,19 @@ static func make(__name):
func set_name(__name:String) -> void:
__name = sanitize_name(__name)
if "" == __name:
printerr("Participant name is empty!")
name = __name
static func sanitize_name(__name:String) -> String:
var invalid = RegEx.new()
# Allow unicode letters and numbers only, with . and _ and -
invalid.compile("[^\\p{L}\\p{N}._-]+")
__name = invalid.sub(__name, '', true)
__name = __name.substr(0, min(__name.length(), 20))
if "" == __name:
printerr("Participant name is empty!")
name = __name
return __name
func get_name() -> String:

4
addons/majority_judgment/MajorityJudgmentPoll.gd

@ -166,6 +166,7 @@ func tally() -> MajorityJudgmentPollTally:
func get_or_create_participant(identifier:String) -> MajorityJudgmentParticipant:
identifier = MajorityJudgmentParticipant.sanitize_name(identifier)
var known_participants = get_participants_index()
if not known_participants.has(identifier):
known_participants[identifier] = MajorityJudgmentParticipant.make(identifier)
@ -192,7 +193,8 @@ func rebuild_participants_index():
func update_participants_index(participant:MajorityJudgmentParticipant):
var identifier = participant.name
# Zealous sanitization, since Participants also handle it on their names
var identifier = MajorityJudgmentParticipant.sanitize_name(participant.name)
if not __participants_index.has(identifier):
__participants_index[identifier] = participant
assert(

Loading…
Cancel
Save