Skip to content

Changset.splitAttributionLines assumes a new line at the end of the string when there are new lines in the op #262

@pdobrev

Description

@pdobrev

https://github.com/Pita/etherpad-lite/blob/master/node/utils/Changeset.js#L1166

splitAttributionLines assumes that if there's one new line in a given op, it will be at the end of the string and will add it as a separate attribution line.

For example, if you have the following op in a changeset:
Line1\n_some text_

it will get pushed as one attribution line, instead of adding Line1 as one line and some text to the next.

I am not sure if you can have this scenario is regular etherpad usage, probably not. I was using etherpad changesets and it's exportHtml functionality for a project of mine, when I bumped into this issue.

Changing the if block to the following fixed it for me:

if (numLines == 1) {
  var newlineEnd = text.indexOf('\n', pos) + 1;
  if (newlineEnd != pos + numChars) {
      // newline not at the end
      op.chars = newlineEnd - pos;
      op.lines = 1;
      appendOp(op);
      numChars -= op.chars;

      op.chars = numChars;
      op.lines = 0;
  } else {
      op.chars = numChars;
      op.lines = 1;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions