[Scummvm-git-logs] scummvm master -> 5f75054fdeab6c433c0c6fe380b9e2d22fc477cc

sev- noreply at scummvm.org
Sat Nov 18 19:21:00 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
5f75054fde COMMON: Skip possible UTF-8 BOM when reading INI files


Commit: 5f75054fdeab6c433c0c6fe380b9e2d22fc477cc
    https://github.com/scummvm/scummvm/commit/5f75054fdeab6c433c0c6fe380b9e2d22fc477cc
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2023-11-18T20:20:56+01:00

Commit Message:
COMMON: Skip possible UTF-8 BOM when reading INI files

Changed paths:
    common/config-manager.cpp
    common/formats/ini-file.cpp


diff --git a/common/config-manager.cpp b/common/config-manager.cpp
index 6f4af2f00c8..a0f6a0a9b86 100644
--- a/common/config-manager.cpp
+++ b/common/config-manager.cpp
@@ -171,6 +171,7 @@ void ConfigManager::addDomain(const String &domainName, const ConfigManager::Dom
 
 
 bool ConfigManager::loadFromStream(SeekableReadStream &stream) {
+	static const byte UTF8_BOM[] = {0xEF, 0xBB, 0xBF};
 	String domainName;
 	String comment;
 	Domain domain;
@@ -197,6 +198,11 @@ bool ConfigManager::loadFromStream(SeekableReadStream &stream) {
 		// Read a line
 		String line = stream.readLine();
 
+		// Skip UTF-8 byte-order mark if added by a text editor.
+		if (lineno == 1 && memcmp(line.c_str(), UTF8_BOM, 3) == 0) {
+			line.erase(0, 3);
+		}
+
 		if (line.size() == 0) {
 			// Do nothing
 		} else if (line[0] == '#') {
diff --git a/common/formats/ini-file.cpp b/common/formats/ini-file.cpp
index 2cbbe421baf..32101f61fcd 100644
--- a/common/formats/ini-file.cpp
+++ b/common/formats/ini-file.cpp
@@ -90,6 +90,7 @@ bool INIFile::loadFromSaveFile(const String &filename) {
 }
 
 bool INIFile::loadFromStream(SeekableReadStream &stream) {
+	static const byte UTF8_BOM[] = {0xEF, 0xBB, 0xBF};
 	Section section;
 	KeyValue kv;
 	String comment;
@@ -105,6 +106,11 @@ bool INIFile::loadFromStream(SeekableReadStream &stream) {
 		// Read a line
 		String line = stream.readLine();
 
+		// Skip UTF-8 byte-order mark if added by a text editor.
+		if (lineno == 1 && memcmp(line.c_str(), UTF8_BOM, 3) == 0) {
+			line.erase(0, 3);
+		}
+
 		line.trim();
 
 		if (line.size() == 0) {




More information about the Scummvm-git-logs mailing list