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

feat: update tmx writer, escaper, and unit test #1049

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

miurahr
Copy link
Member

@miurahr miurahr commented Jun 2, 2024

Pull request type

  • Feature enhancement -> [enhancement]

Which ticket is resolved?

What does this PR change?

  • update TMX test expectation for level2 write
    • use double quote for attribute
    • format indentation and empty line
  • Add TmxEscapingWriterFactory class and unit test with ordinary string, "< & >", Surrogate Pair and invalid one.
  • Use TmxEscapingWriterFactory in TMXWriter2 for TEXT writer

Other information

com.sun.xml.bind.marshaller#escape which is ultimately OmegaT 6.0 and before use is as follows;

public void escape(char[] ch, int start, int length, boolean isAttVal, Writer out) throws IOException {
        int limit = start + length;

        for(int i = start; i < limit; ++i) {
            char c = ch[i];
            if (c == '&' || c == '<' || c == '>' || c == '\r' || c == '\n' && isAttVal || c == '"' && isAttVal) {
                if (i != start) {
                    out.write(ch, start, i - start);
                }

                start = i + 1;
                switch (ch[i]) {
                    case '\n':
                    case '\r':
                        out.write("&#");
                        out.write(Integer.toString(c));
                        out.write(59);
                        break;
                    case '"':
                        out.write("&quot;");
                        break;
                    case '&':
                        out.write("&amp;");
                        break;
                    case '<':
                        out.write("&lt;");
                        break;
                    case '>':
                        out.write("&gt;");
                        break;
                    default:
                        throw new IllegalArgumentException("Cannot escape: '" + c + "'");
                }
            }
        }

        if (start != limit) {
            out.write(ch, start, limit - start);
        }

    }

- use double quote for attribute
- format indentation and empty line

Signed-off-by: Hiroshi Miura <[email protected]>
@miurahr miurahr added this to the 6.1.0 (Require Java 11) milestone Jun 3, 2024

This comment was marked as resolved.

@miurahr
Copy link
Member Author

miurahr commented Jun 3, 2024

This comment was marked as resolved.

This comment was marked as outdated.

This comment was marked as outdated.

@miurahr miurahr changed the title update tmx writer and its test feat: update tmx writer, escaper, and unit test Jun 4, 2024
@miurahr miurahr requested a review from brandelune June 4, 2024 04:31

This comment was marked as outdated.

miurahr added 3 commits June 4, 2024 13:38
- Add TmxEscapingWriterFactory and inner EscapeWriter class
- Set custom factory with P_TEXT_ESCAPER property

Signed-off-by: Hiroshi Miura <[email protected]>
Signed-off-by: Hiroshi Miura <[email protected]>
Signed-off-by: Hiroshi Miura <[email protected]>
@miurahr miurahr force-pushed the topic/miurahr/tmx/serializer-always-escape-gt-entity branch from e6dc5b7 to 0363a9e Compare June 4, 2024 04:46
Signed-off-by: Hiroshi Miura <[email protected]>
@miurahr miurahr force-pushed the topic/miurahr/tmx/serializer-always-escape-gt-entity branch from 37fcf48 to a5ea8d4 Compare June 5, 2024 06:53
@miurahr miurahr marked this pull request as ready for review June 5, 2024 06:54
Signed-off-by: Hiroshi Miura <[email protected]>
@miurahr miurahr marked this pull request as draft June 5, 2024 23:22
@miurahr

This comment was marked as resolved.

@miurahr miurahr marked this pull request as ready for review June 7, 2024 01:23
@miurahr
Copy link
Member Author

miurahr commented Jul 10, 2024

@brandelune this PR is created by your request. Have you already lost the interest?

@miurahr
Copy link
Member Author

miurahr commented Jul 11, 2024

The change here make a modification and an override of a deep and core part of XML writing, marshal. When there is a potential bug, it can break things easily. To reduce sub effect in another place, it only apply a TMXWriter2, TMX writing class. So there is no change in preferences, and other XML related features.

@brandelune
Copy link
Contributor

@brandelune this PR is created by your request. Have you already lost the interest?

Thank you for the nice reminder :-)

@brandelune
Copy link
Contributor

The change here make a modification and an override of a deep and core part of XML writing, marshal. When there is a potential bug, it can break things easily. To reduce sub effect in another place, it only apply a TMXWriter2, TMX writing class. So there is no change in preferences, and other XML related features.

@t-cordonnier do you have an opinion on this ?

@miurahr miurahr requested a review from t-cordonnier July 12, 2024 02:41
@miurahr
Copy link
Member Author

miurahr commented Oct 4, 2024

@t-cordonnier do you have an opinion on this ?

Maybe no opinion.

@miurahr
Copy link
Member Author

miurahr commented Dec 4, 2024

Is it still needed?

@brandelune
Copy link
Contributor

The change here make a modification and an override of a deep and core part of XML writing, marshal. When there is a potential bug, it can break things easily. To reduce sub effect in another place, it only apply a TMXWriter2, TMX writing class. So there is no change in preferences, and other XML related features.

Do you mean that there is no option in the new library to make the behavior the same as in 6.0?

I don’t think we should take risks with such overrides. So I’m still eager to have @t-cordonnier’s opinion.

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.

2 participants