Skip to content

Commit 594fae6

Browse files
committed
fix: partial arabic html live previews should render text wihtout meta utf8 tag
1 parent 36cb8dd commit 594fae6

File tree

9 files changed

+66
-20
lines changed

9 files changed

+66
-20
lines changed

src-node/live-preview.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ function _serveData(getContentAPIToUse, req, res) {
116116
...defaultHeaders,
117117
...customHeaders
118118
};
119-
if(data.textContents && !mergedHeaders['Content-Type'].includes('charset=UTF-8')) {
120-
// https://github.com/orgs/phcode-dev/discussions/1676
121-
mergedHeaders['Content-Type'] = `${mergedHeaders['Content-Type']};charset=UTF-8`;
122-
}
123119
res.writeHead(200, mergedHeaders);
124120
if(data.textContents) {
125121
res.end(data.textContents);

src/extensions/default/HTMLCodeHints/html-lint.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ define(function (require, exports, module) {
3030
const CodeInspection = brackets.getModule("language/CodeInspection"),
3131
Strings = brackets.getModule("strings"),
3232
EditorManager = brackets.getModule("editor/EditorManager"),
33+
ProjectManager = brackets.getModule("project/ProjectManager"),
3334
IndexingWorker = brackets.getModule("worker/IndexingWorker");
3435

3536
IndexingWorker.loadScriptInWorker(`${module.uri}/../worker/html-worker.js`);
@@ -53,9 +54,10 @@ define(function (require, exports, module) {
5354
text,
5455
filePath: fullPath
5556
}).then(lintResult =>{
56-
const editor = EditorManager.getActiveEditor();
57+
const editor = EditorManager.getCurrentFullEditor();
5758
if(!editor || editor.document.file.fullPath !== fullPath) {
58-
reject(new Error("Lint failed as "+ Phoenix.app.getDisplayLocation(fullPath) + " is not active."));
59+
reject(new Error("Lint failed as "+ ProjectManager.getProjectRelativeOrDisplayPath(fullPath)
60+
+ " is not active."));
5961
return;
6062
}
6163
if (lintResult && lintResult.length) {

src/extensions/default/JSLint/JSHint.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ define(function (require, exports, module) {
164164
configFileName = configFileName || CONFIG_FILE_NAME;
165165
const configFilePath = path.join(dir, configFileName);
166166
let displayPath = ProjectManager.makeProjectRelativeIfPossible(configFilePath);
167-
displayPath = Phoenix.app.getDisplayPath(displayPath);
167+
displayPath = ProjectManager.getProjectRelativeOrDisplayPath(displayPath);
168168
DocumentManager.getDocumentForPath(configFilePath).done(function (configDoc) {
169169
if (!ProjectManager.isWithinProject(configFilePath)) {
170170
// this is a rare race condition where the user switches project between the get document call.
@@ -198,7 +198,7 @@ define(function (require, exports, module) {
198198
resolve(mergedConfig);
199199
}).catch(()=>{
200200
let extendDisplayPath = ProjectManager.makeProjectRelativeIfPossible(extendFile.fullPath);
201-
extendDisplayPath = Phoenix.app.getDisplayPath(extendDisplayPath);
201+
extendDisplayPath = ProjectManager.getProjectRelativeOrDisplayPath(extendDisplayPath);
202202
reject("Error parsing JSHint config file: " + extendDisplayPath);
203203
});
204204
}

src/extensionsIntegrated/Phoenix-live-preview/BrowserStaticServer.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ define(function (require, exports, module) {
477477
let html = Mustache.render(markdownHTMLTemplate, templateVars);
478478
resolve({
479479
contents: html,
480-
headers: {'Content-Type': 'text/html; charset=UTF-8'},
480+
headers: {'Content-Type': 'text/html'},
481481
path: fullPath
482482
});
483483
})
@@ -566,9 +566,17 @@ define(function (require, exports, module) {
566566
}
567567
}
568568

569+
let headers;
570+
if(path.endsWith(".htm") || path.endsWith(".html") || path.endsWith(".xhtml") || path.endsWith(".php")) {
571+
headers = {
572+
'Content-Type': 'text/html;charset=UTF-8'
573+
};
574+
}
575+
569576
resolve({
570577
path,
571-
contents: contents
578+
contents: contents,
579+
headers
572580
});
573581
});
574582
};
@@ -627,12 +635,6 @@ define(function (require, exports, module) {
627635
// headers: {'Content-Type': 'text/html'} // optional headers
628636
response.type = 'REQUEST_RESPONSE';
629637
response.requestID = requestID;
630-
if(typeof response.contents === "string"){
631-
// https://github.com/orgs/phcode-dev/discussions/1676
632-
response.headers = {
633-
'Content-Type': 'text/html;charset=UTF-8'
634-
};
635-
}
636638
messageToLivePreviewTabs(response);
637639
})
638640
.catch(console.error);

src/extensionsIntegrated/Phoenix-live-preview/NodeStaticServer.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,17 @@ define(function (require, exports, module) {
408408
}
409409
}
410410

411+
let headers;
412+
if(path.endsWith(".htm") || path.endsWith(".html") || path.endsWith(".xhtml") || path.endsWith(".php")) {
413+
headers = {
414+
'Content-Type': 'text/html;charset=UTF-8'
415+
};
416+
}
417+
411418
resolve({
412419
path,
413-
textContents: contents
420+
textContents: contents,
421+
headers
414422
});
415423
});
416424
};

src/project/ProjectManager.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,19 @@ define(function (require, exports, module) {
580580
return model.makeProjectRelativeIfPossible(absPath);
581581
}
582582

583+
/**
584+
* Gets a generally displayable path that can be shown to the user in most cases.
585+
* Gets the project relative path if possible. If paths is not in project, then if its a platform path(Eg. in tauri)
586+
* it will return the full platform path. If not, then it will return a mount relative path for fs access mount
587+
* folders opened in the bowser. at last, falling back to vfs path. This should only be used for display purposes
588+
* as this path will be changed by phcode depending on the situation in the future.
589+
* @param fullPath
590+
* @returns {string}
591+
*/
592+
function getProjectRelativeOrDisplayPath(fullPath) {
593+
return Phoenix.app.getDisplayPath(makeProjectRelativeIfPossible(fullPath));
594+
}
595+
583596
/**
584597
* Returns the root folder of the currently loaded project, or null if no project is open (during
585598
* startup, or running outside of app shell).
@@ -2239,6 +2252,7 @@ define(function (require, exports, module) {
22392252
exports.getInitialProjectPath = getInitialProjectPath;
22402253
exports.getStartupProjectPath = getStartupProjectPath;
22412254
exports.getProjectRelativePath = getProjectRelativePath;
2255+
exports.getProjectRelativeOrDisplayPath = getProjectRelativeOrDisplayPath;
22422256
exports.getWelcomeProjectPath = getWelcomeProjectPath;
22432257
exports.getPlaceholderProjectPath = getPlaceholderProjectPath;
22442258
exports.getExploreProjectPath = getExploreProjectPath;

test/spec/CodeInspection-integ-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ define(function (require, exports, module) {
536536

537537
expect($("#problems-panel").is(":visible")).toBe(true);
538538
let marks = EditorManager.getActiveEditor().getGutterMarker(1, CodeInspection.CODE_INSPECTION_GUTTER);
539-
expect(marks.title).toBe('\nSome errors here and there at column: 4');
539+
expect(marks.title).toBe('Some errors here and there at column: 4');
540540
marks = $(marks);
541541
expect(marks.find('span').hasClass(expectedClass)).toBeTrue();
542542
return marks;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p id="arabic-text"> 1 يناير 2021 بواسطة </p>

test/spec/LiveDevelopmentMultiBrowser-test.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ define(function (require, exports, module) {
209209
liveDoc = LiveDevMultiBrowser.getCurrentLiveDoc();
210210
await awaitsFor(
211211
function relatedDocsReceived() {
212-
return (Object.getOwnPropertyNames(liveDoc.getRelated().scripts).length > 0);
212+
return (Object.getOwnPropertyNames(liveDoc.getRelated().scripts).length > 0) &&
213+
liveDoc.isRelated(testFolder + "/import1.css");
213214
},
214215
"relatedDocuments.done.received",
215216
10000
@@ -236,6 +237,28 @@ define(function (require, exports, module) {
236237
await endPreviewSession();
237238
}, 30000);
238239

240+
it("should render partial arabic html with correct utf-8 encoding", async function () {
241+
// https://github.com/orgs/phcode-dev/discussions/1676
242+
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["arabicPartial.html"]),
243+
"SpecRunnerUtils.openProjectFiles arabicPartial.html");
244+
await waitsForLiveDevelopmentToOpen();
245+
246+
let result;
247+
await awaitsFor(
248+
function isArabicTextProperlyRendered() {
249+
LiveDevProtocol.evaluate(`document.getElementById('arabic-text').textContent`)
250+
.done((response)=>{
251+
result = JSON.parse(response.result||"");
252+
});
253+
return result === " 1 يناير 2021 بواسطة ";
254+
},
255+
`arabic text to be read correctly`,
256+
5000,
257+
50
258+
);
259+
await endPreviewSession();
260+
}, 30000);
261+
239262
function _isRelatedStyleSheet(liveDoc, fileName) {
240263
let relatedSheets = Object.keys(liveDoc.getRelated().stylesheets);
241264
for(let relatedPath of relatedSheets){
@@ -371,7 +394,7 @@ define(function (require, exports, module) {
371394
});
372395
return result === verifyText;
373396
},
374-
"relatedDocuments.done.received",
397+
`relatedDocuments.done.received verifying ${verifyID} to have ${verifyText}`,
375398
5000,
376399
50
377400
);

0 commit comments

Comments
 (0)