Skip to content

BUG Fix: use HTML value to replace HTML - #97

Open
JoshuaFortriede wants to merge 1 commit into
ome:masterfrom
JoshuaFortriede:bug/mapr_link_symbols
Open

BUG Fix: use HTML value to replace HTML#97
JoshuaFortriede wants to merge 1 commit into
ome:masterfrom
JoshuaFortriede:bug/mapr_link_symbols

Conversation

@JoshuaFortriede

Copy link
Copy Markdown

The original code used the text value of the element when replacing within the HTML. This causes problems when the value contains symbols such as "&" or ">". In these cases .text() != .html(). As such, the replacement won't work.

For instance, if I have a key of "Stain" and a value of "Hematoxylin & Eosin", the .text() of the value is "Hematoxylin & Eosin", but the .html() is "Hematoxylin & Eosin". As such running the replace will not work, and thus will not create the MAPR url.

Note: I do not believe this is the best fix. I think a cleaner approach is to rebuild the HTML entirely in coordination with the iconify function, but that is a bigger refactor.

@will-moore

Copy link
Copy Markdown
Member

Hi @JoshuaFortriede - thanks for the PR.
I wonder if you could exclude all the JavaScript linting changes from your commit? I know it can be annoying to have badly formatted code, but it's impossible to see where you made the fix.

It also partly obscures the commit/blame history of the file.

If you want to re-format the file in a follow-up commit, perhaps you can add that commit to a file as described in https://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/
(and https://docs.github.com/en/repositories/working-with-files/using-files/viewing-and-understanding-files#ignore-commits-in-the-blame-view)

Thanks

@JoshuaFortriede

Copy link
Copy Markdown
Author

Yes, sorry about that. I saved without my linting and the new commit is there.

var _url = location.protocol + "//" + location.host + "{% url 'maprindex' %}" + keys2menu[_key] +"/?value=" + encodeURIComponent(_val);
$chvalue.html($chvalue.html().replace(_val, '<a href="' + _url + '">' + _val + '</a>'));
// replace the original HTML value with a link to the internal mapr URL
$chvalue.html($chvalue.html().replace(_valHTML, '<a href="' + _url + '">' + _val + '</a>'));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that.

Since _valHTML is the same as $chvalue.html(), this is equivalent to

_valHTML.replace(_valHTML, '<a href="' + _url + '">' + _val + '</a>')

which is equivalent to

'<a href="' + _url + '">' + _val + '</a>'

Maybe I'm just missing something in the reading of this (without running it)?

I need to get omero-mapr set up on our test server so we can test this and #98..

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants