MCPcopy
hub / github.com/vercel/next.js / fixMojibake

Function fixMojibake

packages/next/src/server/lib/fix-mojibake.ts:4–14  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

2// and should only be utf8 characters so this fixes
3// incorrectly encoded values
4export function fixMojibake(input: string): string {
5 // Convert each character's char code to a byte
6 const bytes = new Uint8Array(input.length)
7 for (let i = 0; i < input.length; i++) {
8 bytes[i] = input.charCodeAt(i)
9 }
10
11 // Decode the bytes as proper UTF-8
12 const decoder = new TextDecoder('utf-8')
13 return decoder.decode(bytes)
14}

Callers 2

handleRequestImplFunction · 0.90

Calls 2

charCodeAtMethod · 0.80
decodeMethod · 0.80

Tested by

no test coverage detected