Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for windows-1252 character encoding #4576

Closed
codyebberson opened this issue May 20, 2024 · 1 comment · Fixed by #4621
Closed

Add support for windows-1252 character encoding #4576

codyebberson opened this issue May 20, 2024 · 1 comment · Fixed by #4621
Assignees

Comments

@codyebberson
Copy link
Member

iconv-lite supports windows-1252 and is already in the dependency tree for nodemailer: https://www.npmjs.com/package/iconv-lite

Create Middleware for Encoding Conversion

You need to create a middleware that checks the Content-Type of the response and converts the content to CP1252 if required.

const iconv = require('iconv-lite');

function cp1252Middleware(req, res, next) {
    const originalSend = res.send;

    res.send = function (data) {
        if (res.getHeader('Content-Type') === 'text/plain; charset=windows-1252') {
            if (typeof data === 'string') {
                data = iconv.encode(data, 'cp1252');
                // Set the correct Content-Length for the encoded data
                res.setHeader('Content-Length', Buffer.byteLength(data));
            }
        }
        
        originalSend.apply(res, [data]);
    };

    next();
}

Use the Middleware in Your Express Application

You must apply this middleware to your Express application. It should be added before any routes that may send text/plain; charset=windows-1252 responses.

const express = require('express');
const app = express();

// Use the cp1252 encoding middleware
app.use(cp1252Middleware);

// Example route
app.get('/', (req, res) => {
    res.setHeader('Content-Type', 'text/plain; charset=windows-1252');
    res.send('Hello, this is some text that will be encoded in CP1252!');
});

// Start the server
const PORT = 3000;
app.listen(PORT, () => {
    console.log(`Server is running on http://localhost:${PORT}`);
});
github-merge-queue bot pushed a commit that referenced this issue May 27, 2024
* Fixes #4576 - Windows 1252 character encoding

* Add encoding as Endpoint.address query param

* Added cli options
@ThatOneBro
Copy link
Member

Closed as completed in #4594

@ThatOneBro ThatOneBro added this to the May 31st, 2024 milestone May 28, 2024
medplumbot added a commit that referenced this issue Jun 2, 2024
Updating sample HL7 bot to include ADT-08 messages (#4591)Dependency upgrades 2024-05-27 (#4593)
feat: enable unit testing subscription criteria (#4581)
feat(fhircast): properly respond to `unsubscribe` request (#4590)
Fixes #4576 - Windows 1252 character encoding (#4594)
refactor(subscriptions): skip `bullmq` for WS subs, push all WS subs thru one Redis channel (#4585)
Added fhirpath test data (#4598)
Fix several fhirpath functions taking `other` Atom and implement subsetOf & supersetOf (#4601)
Use nested transactions with stronger isolation (#4583)
Support Database SSL config from Env (#4597)
Parse ADT example  (#4596)
Better PATCH error messages (#4607)
Respect AccessPolicy.resource.{readonlyFields,hiddenFields} in ResourceForm (#4588)
Fix IAM policy resource strings (#4603)
Fixes #4440 - backslash escaped commas in search values (#4609)
Fixes #4147 - formatSearchQuery with _include:iterate (#4610)
Fixes #4462 - configurable Bot AuditEvent.outcomeDesc max length (#4612)
Fixes #4531 - choice-of-type definitions and getExtensionValue() (#4611)
Allow Bot to return Binary (#4595)
Remove spurious console.warn (#4616)
Fixed flaky repo tests (#4618)
Fixes #4617 - replace Google QR code API (#4619)
github-merge-queue bot pushed a commit that referenced this issue Jun 2, 2024
Updating sample HL7 bot to include ADT-08 messages (#4591)Dependency upgrades 2024-05-27 (#4593)
feat: enable unit testing subscription criteria (#4581)
feat(fhircast): properly respond to `unsubscribe` request (#4590)
Fixes #4576 - Windows 1252 character encoding (#4594)
refactor(subscriptions): skip `bullmq` for WS subs, push all WS subs thru one Redis channel (#4585)
Added fhirpath test data (#4598)
Fix several fhirpath functions taking `other` Atom and implement subsetOf & supersetOf (#4601)
Use nested transactions with stronger isolation (#4583)
Support Database SSL config from Env (#4597)
Parse ADT example  (#4596)
Better PATCH error messages (#4607)
Respect AccessPolicy.resource.{readonlyFields,hiddenFields} in ResourceForm (#4588)
Fix IAM policy resource strings (#4603)
Fixes #4440 - backslash escaped commas in search values (#4609)
Fixes #4147 - formatSearchQuery with _include:iterate (#4610)
Fixes #4462 - configurable Bot AuditEvent.outcomeDesc max length (#4612)
Fixes #4531 - choice-of-type definitions and getExtensionValue() (#4611)
Allow Bot to return Binary (#4595)
Remove spurious console.warn (#4616)
Fixed flaky repo tests (#4618)
Fixes #4617 - replace Google QR code API (#4619)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants