Merge branch 'fix-40-percent-issue' into 'develop'

Fix: #40 - Base64decode crashed when there was a '%' in a string

See merge request ldc-web/projets/nature-and-respect!49
This commit is contained in:
Vincent BRIDIER 2024-06-17 12:54:39 +00:00
commit 212b41a451

View file

@ -39,13 +39,13 @@
</template>
<script lang="ts">
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import axios from "axios";
import { defineComponent } from "vue";
import parseLaravelErrorMessages from "./../../modules/parseLaravelErrorMessages";
import route from "./../../modules/route";
import toast from "./../../modules/toast";
import trans from "./../../modules/trans";
import { defineComponent } from "vue";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
export default defineComponent({
name: "NewsInfiniteLoaderComponent",
@ -118,10 +118,17 @@ export default defineComponent({
});
},
base64decode(str: string): string {
/**
* Fix issue #40: Problem when there's a '%' in a string.
* https://stackoverflow.com/a/30106551
*/
let decode = atob(str).replace(
"/[\x80-\uffff]/g",
(m) => `%${m.charCodeAt(0).toString(16).padStart(2, "0")}`
);
).split("").map(function(c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
}).join("");
return decodeURIComponent(decode);
},
},