Skip to content

Commit 6385938

Browse files
Merge pull request #144 from ISISComputingGroup/encoding
fix encoding
2 parents 9647585 + 277bafb commit 6385938

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

app/components/PVutils.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,20 @@ test("getPvValue returns the text value when text is provided", () => {
192192
expect(result).toBe("Hello World");
193193
});
194194

195-
test("getPvValue decodes and return the base64 value when b64byt is provided", () => {
195+
test("getPvValue decodes and return the base64 value with strange characters when b64byt is provided", () => {
196+
const updatedPV = {
197+
type: "update",
198+
pv: "test",
199+
b64byt:
200+
"wqHCosKjwqTCpcKmwqfCqMKpwqrCq8Kswq7Cr8KwwrHCssKzwrTCtcK2wrfCuMK5wrrCu8K8wr3CvsK/w4DDgcOCw4PDhMOFw4bDh8OIw4nDisOLw4zDjcOOw4/DkMORw5LDk8OUw5XDlsOXw5jDmcOaw5vDnMOdw57Dn8Ogw6HDosOjw6TDpcOmw6fDqMOpw6rDq8Osw63DrsOvw7DDscOyw7PDtMO1w7bDt8O4w7nDusO7w7zDvcO+w78=",
201+
};
202+
const result = getPvValue(updatedPV);
203+
expect(result).toBe(
204+
"¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ",
205+
);
206+
});
207+
208+
test("getPvValue decodes and returns base64 value when b64byt is provided", () => {
196209
const updatedPV = { type: "update", pv: "test", b64byt: "SGVsbG8gV29ybGQ=" }; // Base64 for 'Hello World'
197210
const result = getPvValue(updatedPV);
198211
expect(result).toBe("Hello World");

app/components/PVutils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function getPvValue(
6060
return updatedPV.text;
6161
} else if (updatedPV.b64byt != null) {
6262
// PV value is base64 encoded
63-
return atob(updatedPV.b64byt);
63+
return Buffer.from(updatedPV.b64byt, "base64").toString("utf-8");
6464
} else if (updatedPV.value != null) {
6565
// PV value is a number
6666
return updatedPV.value;

0 commit comments

Comments
 (0)