8000 PrimaveraXERFileWriter encodes LF in memo text as 0x7F 0x7F but leaves CR, so notes with CRLF line breaks don't survive a write and read · Issue #978 · joniles/mpxj · GitHub
[go: up one dir, main page]

Skip to content

PrimaveraXERFileWriter encodes LF in memo text as 0x7F 0x7F but leaves CR, so notes with CRLF line breaks don't survive a write and read #978

Open

Description

@james-wagner11

P6 stores activity notes (TASKMEMO) as HTML with Windows line breaks. When PrimaveraXERFileWriter writes a note whose HTML contains \r\n, it turns each \n into 0x7F 0x7F, as XER expects, but keeps each \r as a raw carriage return in the row:

%R	1	1	1	1	<HTML><BODY>\r\x7f\x7f<P>Line one</P>\r\x7f\x7f<P>line two</P>\r\x7f\x7f</BODY></HTML>

Reading that XER back with PrimaveraXERFileReader gives an empty note here. On real P6 notes it keeps only the text before the first line break. The same note with \n-only line breaks round-trips intact.

Repro

MPXJ 16.10.0 (PyPI wheel, JPype 1.7.1, OpenJDK 17): one task with

task.setNotesObject(new HtmlNotes("<HTML><BODY>\r\n<P>Line one</P>\r\n<P>line two</P>\r\n</BODY></HTML>"));

then an XER write, then an XER read. getNotes() reads back as ''. With LF-only line breaks it reads back as 'Notes\nLine one\n\nline two'.

Full Python (JPype) script; the calls are the same in Java
import jpype, mpxj  # noqa: F401
jpype.startJVM()
from java.io import ByteArrayOutputStream, ByteArrayInputStream
from java.time import LocalDateTime
from org.mpxj import ProjectFile, Duration, TimeUnit, ActivityType, PercentCompleteType, HtmlNotes
from org.mpxj.primavera import PrimaveraXERFileWriter, PrimaveraXERFileReader

def roundtrip(html, label):
    p = ProjectFile()
    cal = p.addDefaultBaseCalendar()
    p.getProjectProperties().setDefaultCalendar(cal)
    p.getProjectProperties().setStartDate(LocalDateTime.of(2026, 1, 5, 8, 0))
    t = p.addTask(); t.setName("A1000"); t.setActivityID("A1000")
    t.setActivityType(ActivityType.TASK_DEPENDENT); t.setCalendar(cal)
    t.setPercentCompleteType(PercentCompleteType.DURATION)
    d = Duration.getInstance(40, TimeUnit.HOURS)
    t.setDuration(d); t.setRemainingDuration(d); t.setPlannedDuration(d)
    t.setNotesObject(HtmlNotes(html))
    out = ByteArrayOutputStream(); PrimaveraXERFileWriter().write(p, out)
    back = PrimaveraXERFileReader().read(ByteArrayInputStream(out.toByteArray()))
    got = [x for x in back.getTasks() if str(x.getActivityID()) == "A1000"][0]
    print(f"{label}: read back = {str(got.getNotes())!r}")

roundtrip("<HTML><BODY>\r\n<P>Line one</P>\r\n<P>line two</P>\r\n</BODY></HTML>", "crlf")  # ''
roundtrip("<HTML><BODY>\n<P>Line one</P>\n<P>line two</P>\n</BODY></HTML>", "lf")          # 'Notes\nLine one\n\nline two'

Expected

The writer encodes a CRLF pair as 0x7F 0x7F, as P6's own XER export does, and a lone CR the same way, so notes survive a write and read.

Where

XerWriter::formatNotes does result.replace("\n", "\u007F\u007F") and leaves \r alone. That line is unchanged in 16.11.0. Something like result.replace("\r\n", "\u007F\u007F").replace("\r", "\u007F\u007F").replace("\n", "\u007F\u007F") would match P6, but I haven't tested it.

Scale

Every note on a real P6 schedule we read from the database (28 of 28) came back from an MPXJ-written XER cut to its first line.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0