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

Escaping Tags in XLIFF #2936

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Escaping Tags in XLIFF #2936

wants to merge 11 commits into from

Conversation

neo773
Copy link
Contributor

@neo773 neo773 commented Feb 23, 2025

This PR adds support for escaping HTML tags in XLIFF

Check list

  • Import
  • Export
  • Tests
  • Docs PR
  • CDN (Complete but unable to test it due to local dev environment issues)

/claim #2912
/closes #2912

fun escapeHtmlTags(text: String): String {
var result = text.replace("\"", """)

val regex: Regex = "<(/?[^>]+)>".toRegex()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho no need to compile regex every function call since it's always same, I'd extract it to private variable. Also maybe question of tag validity is on the table??? because this regex will also match for example <<<p> which is not a valid tag according to specification (correct me if I'm wrong) @JanCizmar what is your take on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validity of the markup is guaranteed by the Parser, Escaping takes place after Parser has successfully parsed it

If you try it with invalid markup it will throw an error

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to replace all the possible xml syntax, but I am proposing the Apache commons solution in my review.

@cardvvs Thanks for the review anyway.

@@ -50,7 +51,13 @@ class Xliff12FileProcessor(
transUnitId: String,
language: String,
) {
val converted = convertMessage(text, language)
val textToConvert =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes any sense to escape html when importing. This wasn't in the scope of the task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove it, I only added it since the author of the issue mentioned it

image

@field:Parameter(
description = ESCAPE_HTML_DESCRIPTION,
)
override var escapeHtml: Boolean? = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add documentation comment.

/** Enabling or disabling HTML escaping for XLIFF format. Some tools expect the XML/HTML tags escaped and don't accept raw unescaped tags. */

@@ -129,4 +129,7 @@ class ContentDeliveryConfig(

@ActivityLoggedProp
override var fileStructureTemplate: String? = null

@ActivityLoggedProp
override var escapeHtml: Boolean? = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason to make it nullable. Make it false by default and add @ColumnDefault annotation so tests won't fail.

@neo773 neo773 closed this Feb 24, 2025
@neo773 neo773 reopened this Feb 24, 2025
@neo773 neo773 marked this pull request as ready for review February 24, 2025 17:47
@neo773 neo773 requested a review from JanCizmar February 24, 2025 17:47
@neo773
Copy link
Contributor Author

neo773 commented Feb 24, 2025

Apologies for the spam, the branch ran into several issues and I had to reset it and do a merge from a clean branch.
@JanCizmar It has addressed the changes you requested.

@JanCizmar
Copy link
Contributor

Hey! So does it currently also work with the CDN and is it tested?

@neo773
Copy link
Contributor Author

neo773 commented Feb 26, 2025

@JanCizmar
I’ve been trying to enable CDN to test it but haven’t had any luck so far.
Will look into it again today.

@neo773
Copy link
Contributor Author

neo773 commented Feb 26, 2025

@JanCizmar
Got CDN working with Cloudflare and it seems to be working as expected

a.mp4

@JanCizmar
Copy link
Contributor

Hello! Thanks a lot it's great. I would like to see a cypress test, which tests that the CD configuration is actually saved with the the new checkbox value.

That's my last input before I jump on the final Code Review.

Thanks a lot for the persistence on this.

@JanCizmar
Copy link
Contributor

Hello! Are there any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Escaping Tags in XLIFF export/import
3 participants