Skip to content

Commit 52d7c94

Browse files
authored
chore: rewrite for pure utf-8 content handling (#511)
1 parent 6f1a6d6 commit 52d7c94

File tree

75 files changed

+1728
-934
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1728
-934
lines changed

src/TibiaDataUtils.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"html"
5-
"io"
65
"log"
76
"net/url"
87
"os"
@@ -13,7 +12,6 @@ import (
1312
"unicode/utf8"
1413

1514
"golang.org/x/text/cases"
16-
"golang.org/x/text/encoding/charmap"
1715
"golang.org/x/text/language"
1816
"golang.org/x/text/unicode/norm"
1917
)
@@ -186,16 +184,6 @@ func RemoveHtmlTag(s string) string {
186184
return s
187185
}
188186

189-
// TibiaDataConvertEncodingtoISO88591 func - convert string from UTF-8 to latin1 (ISO 8859-1)
190-
func TibiaDataConvertEncodingtoISO88591(data string) (string, error) {
191-
return charmap.ISO8859_1.NewEncoder().String(data)
192-
}
193-
194-
// TibiaDataConvertEncodingtoUTF8 func - convert string from latin1 (ISO 8859-1) to UTF-8
195-
func TibiaDataConvertEncodingtoUTF8(data io.Reader) io.Reader {
196-
return norm.NFKC.Reader(charmap.ISO8859_1.NewDecoder().Reader(data))
197-
}
198-
199187
// TibiaDataSanitizeEscapedString func - run unescape string on string
200188
func TibiaDataSanitizeEscapedString(data string) string {
201189
return html.UnescapeString(data)

src/TibiaWorldsWorld_test.go

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ import (
88
"github.com/tibiadata/tibiadata-api-go/src/static"
99
)
1010

11+
func TestWorldAntica(t *testing.T) {
12+
file, err := static.TestFiles.Open("testdata/worlds/world/Antica.html")
13+
if err != nil {
14+
t.Fatalf("file opening error: %s", err)
15+
}
16+
defer file.Close()
17+
18+
data, err := io.ReadAll(file)
19+
if err != nil {
20+
t.Fatalf("File reading error: %s", err)
21+
}
22+
23+
worldJson, err := TibiaWorldsWorldImpl("Antica", string(data), "https://www.tibia.com/community/?subtopic=worlds&world=Antica")
24+
if err != nil {
25+
t.Fatal(err)
26+
}
27+
28+
assert := assert.New(t)
29+
world := worldJson.World
30+
information := worldJson.Information
31+
32+
assert.Equal("https://www.tibia.com/community/?subtopic=worlds&world=Antica", information.TibiaURLs[0])
33+
34+
umlautPlayer := world.OnlinePlayers[171]
35+
assert.Equal("Nöber", umlautPlayer.Name)
36+
assert.Equal(455, umlautPlayer.Level)
37+
assert.Equal("Elder Druid", umlautPlayer.Vocation)
38+
}
39+
1140
func TestWorldEndebra(t *testing.T) {
1241
file, err := static.TestFiles.Open("testdata/worlds/world/Endebra.html")
1342
if err != nil {
@@ -70,25 +99,25 @@ func TestWorldPremia(t *testing.T) {
7099
world := worldJson.World
71100

72101
assert.Equal("Premia", world.Name)
73-
assert.Equal("offline", world.Status)
74-
assert.Equal(0, world.PlayersOnline)
102+
assert.Equal("online", world.Status)
103+
assert.Equal(53, world.PlayersOnline)
75104
assert.Equal(531, world.RecordPlayers)
76105
assert.Equal("2013-08-08T15:30:30Z", world.RecordDate)
77106
assert.Equal("2002-04", world.CreationDate)
78107
assert.Equal("Europe", world.Location)
79108
assert.Equal("Open PvP", world.PvpType)
80109
assert.True(world.PremiumOnly)
81110
assert.Equal("regular", world.TransferType)
82-
assert.Equal(4, len(world.WorldsQuestTitles))
83-
assert.Equal("Rise of Devovorga", world.WorldsQuestTitles[0])
84-
assert.Equal("Bewitched", world.WorldsQuestTitles[1])
85-
assert.Equal("The Colours of Magic", world.WorldsQuestTitles[2])
111+
assert.Equal(7, len(world.WorldsQuestTitles))
112+
assert.Equal("The Lightbearer", world.WorldsQuestTitles[0])
113+
assert.Equal("Rise of Devovorga", world.WorldsQuestTitles[1])
114+
assert.Equal("Annual Autumn Vintage", world.WorldsQuestTitles[2])
86115
assert.Equal("A Piece of Cake", world.WorldsQuestTitles[3])
87116
assert.True(world.BattleyeProtected)
88117
assert.Equal("2017-09-05", world.BattleyeDate)
89118
assert.Equal("regular", world.GameWorldType)
90119
assert.Empty(world.TournamentWorldType)
91-
assert.Equal(0, len(world.OnlinePlayers))
120+
assert.Equal(53, len(world.OnlinePlayers))
92121
}
93122

94123
func TestWorldWintera(t *testing.T) {

src/static/testdata/boostablebosses/boostablebosses.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
<!DOCTYPE html>
3-
<html>
3+
<html lang="en">
44
<head>
55
<title>Tibia - Free Multiplayer Online Role Playing Game - Library</title>
6-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
6+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
77
<meta name="author" content="CipSoft GmbH" />
88
<meta http-equiv="content-language" content="en" />
99
<meta name="keywords" content="free online game, free multiplayer game, free online rpg, free mmorpg, mmorpg, mmog, online role playing game, online multiplayer game, internet game, online rpg, rpg" />

src/static/testdata/characters/Akayev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html lang="en">
44
<head>
55
<title>Tibia - Free Multiplayer Online Role Playing Game - Community</title>
6-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
6+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
77
<meta name="author" content="CipSoft GmbH" />
88
<meta http-equiv="content-language" content="en" />
99
<meta name="keywords" content="free online game, free multiplayer game, free online rpg, free mmorpg, mmorpg, mmog, online role playing game, online multiplayer game, internet game, online rpg, rpg" />

src/static/testdata/characters/Akura Aleus.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

33
<!DOCTYPE html>
4-
<html>
4+
<html lang="en">
55
<head>
66
<title>Tibia - Free Multiplayer Online Role Playing Game - Community</title>
7-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
7+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
88
<meta name="author" content="CipSoft GmbH" />
99
<meta http-equiv="content-language" content="en" />
1010
<meta name="keywords" content="free online game, free multiplayer game, free online rpg, free mmorpg, mmorpg, mmog, online role playing game, online multiplayer game, internet game, online rpg, rpg" />

src/static/testdata/characters/Borttagna Gubben.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
<!DOCTYPE html>
3-
<html>
3+
<html lang="en">
44
<head>
55
<title>Tibia - Free Multiplayer Online Role Playing Game - Community</title>
6-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
6+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
77
<meta name="author" content="CipSoft GmbH" />
88
<meta http-equiv="content-language" content="en" />
99
<meta name="keywords" content="free online game, free multiplayer game, free online rpg, free mmorpg, mmorpg, mmog, online role playing game, online multiplayer game, internet game, online rpg, rpg" />

src/static/testdata/characters/Darkside Rafa.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
<!DOCTYPE html>
3-
<html>
3+
<html lang="en">
44
<head>
55
<title>Tibia - Free Multiplayer Online Role Playing Game - Community</title>
6-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
6+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
77
<meta name="author" content="CipSoft GmbH" />
88
<meta http-equiv="content-language" content="en" />
99
<meta name="keywords" content="free online game, free multiplayer game, free online rpg, free mmorpg, mmorpg, mmog, online role playing game, online multiplayer game, internet game, online rpg, rpg" />

src/static/testdata/characters/Jowjow Invencivel.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22

33
<!DOCTYPE html>
4-
<html>
4+
<html lang="en">
55
<head>
66
<title>Tibia - Free Multiplayer Online Role Playing Game - Community</title>
7-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
7+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
88
<meta name="author" content="CipSoft GmbH" />
99
<meta http-equiv="content-language" content="en" />
1010
<meta name="keywords" content="free online game, free multiplayer game, free online rpg, free mmorpg, mmorpg, mmog, online role playing game, online multiplayer game, internet game, online rpg, rpg" />

src/static/testdata/characters/Luminals.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
<!DOCTYPE html>
3-
<html>
3+
<html lang="en">
44
<head>
55
<title>Tibia - Free Multiplayer Online Role Playing Game - Community</title>
6-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
6+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
77
<meta name="author" content="CipSoft GmbH" />
88
<meta http-equiv="content-language" content="en" />
99
<meta name="keywords" content="free online game, free multiplayer game, free online rpg, free mmorpg, mmorpg, mmog, online role playing game, online multiplayer game, internet game, online rpg, rpg" />

src/static/testdata/characters/Mieluffy.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
<!DOCTYPE html>
3-
<html>
3+
<html lang="en">
44
<head>
55
<title>Tibia - Free Multiplayer Online Role Playing Game - Community</title>
6-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
6+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="description" content="Tibia is a free massively multiplayer online role-playing game (MMORPG). Join this fascinating game that has thousands of fans from all over the world! - http://www.tibia.com" />
77
<meta name="author" content="CipSoft GmbH" />
88
<meta http-equiv="content-language" content="en" />
99
<meta name="keywords" content="free online game, free multiplayer game, free online rpg, free mmorpg, mmorpg, mmog, online role playing game, online multiplayer game, internet game, online rpg, rpg" />

0 commit comments

Comments
 (0)