woofmark icon indicating copy to clipboard operation
woofmark copied to clipboard

History code appearing upon refreshing page?

Open danvim opened this issue 9 years ago • 11 comments

I have been testing the software and I think I've found a bug?

I'm using Firefox Nightly 41,

Problem: Texts unexpected appended to editor upon refresh

Expected Text: space

Resulted Text: First time. spaceWoofmarkSelectionOpenMarkergbdhcWoofmarkSelectionCloseMarkergbdhc Second time. spaceWoofmarkSelectionOpenMarkerecaacbhWoofmarkSelectionCloseMarkerecaacbh

Procedures: Input space or any text into WYSIWYG mode, refresh page.

Analysis: The string "WoofmarkSelectionOpenMarker" + code string + "WoofmarkSelectionCloseMarker" + repeated code string is appended to text upon every refresh on WYSIWYG mode with some text input.

danvim avatar Jun 12 '15 14:06 danvim

Weird. These are used to persist the selection across input modes, but shouldn't stay in the editor. Can you invetigate this issue yourself? Relevant code is here: https://github.com/bevacqua/woofmark/blob/master/src/rememberSelection.js#L24

bevacqua avatar Jun 12 '15 15:06 bevacqua

https://github.com/bevacqua/woofmark/blob/master/dist/woofmark.js#L3488-3490

capture

Somehow, your script failed to replace the rmarkers.

danvim avatar Jun 12 '15 15:06 danvim

capture

You script failed to find the rmarker because the page has been _refreshed_ and a new code is generated.

You should probably create an open tag and an end tag wrapping the code, so as to use regex to find it even if the code is irrelevant, e.g.

WoofmarkSelectionOpenMarker{{abcdefgh}} WoofmarkSelectionCloseMarker{{abcdefgh}}

https://github.com/bevacqua/woofmark/blob/master/dist/woofmark.js#L3456

danvim avatar Jun 12 '15 15:06 danvim

Could you create a PR with the fix?

bevacqua avatar Jun 12 '15 16:06 bevacqua

Replacing https://github.com/bevacqua/woofmark/blob/master/dist/woofmark.js#L3457-3459

with

var code = Math.random().toString(18).substr(2).replace(/\d+/g, '');
var open = 'WoofmarkSelectionOpenMarker{{' + code + '}}';
var close = 'WoofmarkSelectionCloseMarker{{' + code + '}}';
//var rmarkers = new RegExp(open + '|' + close, 'g');
var rmarkers = new RegExp('WoofmarkSelectionOpenMarker{{.+}}|WoofmarkSelectionCloseMarker{{.+}}', 'g');

solves the problem with refreshing the page in WYSIWYG mode, but I'm sure the code is there for a reason. If the regex matches any code, would it break the program?

Sorry, but I'm really no expert at JavaScript

danvim avatar Jun 13 '15 03:06 danvim

I can't reproduce this either. Please help me reproduce

bevacqua avatar Jul 17 '15 16:07 bevacqua

Similar to the other issue, I'm using Nightly, but Firefox should do.

Steps:

  1. Use http://bevacqua.github.io/woofmark/
  2. Use "wysiwyg" mode.
  3. Delete everything and paste in space.
  4. Click the refresh button on the right of the address bar.
  5. You should notice the editor now contains WoofmarkSelectionOpenMarkerefcdagfWoofmarkSelectionCloseMarkerefcdagfspace

danvim avatar Jul 18 '15 01:07 danvim

@bevacqua I discovered that, on Firefox, it tried to keep the content, but on Chrome, the editor resets. Perhaps you haven't considered Firefox for testing?

danvim avatar Jul 18 '15 01:07 danvim

I haven't done thorough testing on Firefox. Can you work out a fix for this issue?

bevacqua avatar Jul 19 '15 01:07 bevacqua

@bevacqua If you look up, I've tried a fix for the problem, accounting that Firefox tries to save what was inputted. I wrapped the code with brackets so they can be detected and removed.

Sorry, but I'm really no expert in JavaScript, my "fixes" might just be silly codings :(

danvim avatar Jul 19 '15 02:07 danvim

The input autocompletion is probably the culprit here. You can try disabling the autocompletion as per the linked article if you do not want the browser to "remember" the modified content on refresh.

blindwaves avatar Sep 03 '15 09:09 blindwaves