Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@

### Bug fixes

- **Media filenames keep their punctuation** when inserted into an entry.
- **Changing a password ends the account's other sessions.** Saving a new
password in the profile, an administrator's reset, or disabling an account
now logs out that user's other browsers at their next Roller UI page; the
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/webapp/WEB-INF/jsps/editor/EntryEditor.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,14 @@
function onSelectMediaFile(name, url, isImage, hasThumbnail) {
$("#mediafile_edit_lightbox").modal("hide");
$("#mediaFileEditor").attr('src', 'about:blank');
var link = $('<a>').attr('href', url);
if (isImage === "true") {
var src = hasThumbnail === "false" ? url : url + '?t=true';
insertMediaFile('<a href="' + url + '"><img src="' + src + '" alt="' + name + '" /></a>');
link.append($('<img>').attr({src: src, alt: name}));
} else {
insertMediaFile('<a href="' + url + '">' + name + '</a>');
link.text(name);
}
insertMediaFile(link.prop('outerHTML'));
}

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

package org.apache.roller.selenium.editor;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -40,7 +43,7 @@
/**
* Runs the entry editor's rich-editor-content.js in a blank page in Firefox,
* without a Roller server: which entries open in the HTML textarea instead of
* the rich editor, and where the textarea fallback inserts media files.
* the rich editor, and how media is inserted in the entry editor.
*
* <p>The module's verify phase starts Roller in Jetty first. To run just this
* class without it, from it-selenium:
Expand Down Expand Up @@ -162,6 +165,11 @@ public class RichEditorContentIT {
// the rich editor loads entries with jQuery's html()
private static final String JQUERY = "META-INF/resources/webjars/jquery/3.7.1/jquery.js";

private static final Pattern MEDIA_CHOOSER_CALLBACK =
Pattern.compile("(?ms)^ function onSelectMediaFile\\(.*?^ }");
private static final String MEDIA_NAME = "Notes ' \" <draft> & edits";
private static final String MEDIA_URL = "/blog/mediaresource/123";

private static WebDriver driver;
private static String script;
private static String jquery;
Expand Down Expand Up @@ -258,6 +266,45 @@ public void whatStaysInTheRichEditorHasNoEventHandlersOnceJqueryLoadsIt() {
assertEquals("should open in the textarea:", "", missed.toString());
}

@Test
public void mediaLinkKeepsFilenamePunctuation() throws IOException {
selectMedia(false, false);
assertEquals(MEDIA_NAME, js("return insertedMedia.querySelector('a').textContent;"));
}

@Test
public void mediaImageWithThumbnailKeepsFilenamePunctuation() throws IOException {
selectMedia(true, true);
assertEquals(MEDIA_NAME, js("return insertedMedia.querySelector('img').alt;"));
assertEquals(MEDIA_URL + "?t=true", js("return insertedMedia.querySelector('img').getAttribute('src');"));
}

@Test
public void mediaImageWithoutThumbnailKeepsFilenamePunctuation() throws IOException {
selectMedia(true, false);
assertEquals(MEDIA_NAME, js("return insertedMedia.querySelector('img').alt;"));
assertEquals(MEDIA_URL, js("return insertedMedia.querySelector('img').getAttribute('src');"));
}

private static void selectMedia(boolean isImage, boolean hasThumbnail) throws IOException {
String jsp = Files.readString(Paths.get("../app/src/main/webapp/WEB-INF/jsps/editor/EntryEditor.jsp"));
Matcher callback = MEDIA_CHOOSER_CALLBACK.matcher(jsp);
assertTrue("media chooser callback is present", callback.find());

js("var s = document.createElement('script');"
+ "s.textContent = arguments[0];"
+ "document.head.appendChild(s);", jquery + "\n" + callback.group());
// Parse the markup passed to the editor without loading a media resource.
js("jQuery.fn.modal = function () { return this; };"
+ "window.insertMediaFile = function (html) {"
+ " var template = document.createElement('template');"
+ " template.innerHTML = html;"
+ " window.insertedMedia = template.content;"
+ "};"
+ "onSelectMediaFile(arguments[0], arguments[1], arguments[2], arguments[3]);",
MEDIA_NAME, MEDIA_URL, Boolean.toString(isImage), Boolean.toString(hasThumbnail));
}

private static String insert(String text) {
js("RollerRichEditor.insertAtCursor(document.getElementById('edit_content'), arguments[0]);",
text);
Expand Down
Loading