Skip to content

Commit

Permalink
Merge pull request #324 from ncats/codeCommentsHtmlValidator
Browse files Browse the repository at this point in the history
code comments HTML validation
  • Loading branch information
blueSwordfish authored Apr 11, 2024
2 parents de9fa82 + ffd3266 commit 1c919bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Created by epuzanov on 7/25/22.
*/
public final class HtmlUtil {
private static final Set<String> safetags = Stream.of("i", "small", "sub", "sup").collect(Collectors.toSet());
private static final Set<String> safetags = Stream.of("br", "i", "small", "sub", "sup").collect(Collectors.toSet());
private static class TruncateVisitor implements NodeVisitor {
private int maxLen = 0;
private Element dst;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import gsrs.module.substance.repository.ReferenceRepository;
import gsrs.module.substance.repository.SubstanceRepository;
import gsrs.module.substance.utils.HtmlUtil;
import ix.core.models.Keyword;
import ix.core.util.LogUtil;
import ix.core.validator.GinasProcessingMessage;
Expand Down Expand Up @@ -119,6 +120,16 @@ public void validate(Substance s, Substance objold, ValidatorCallback callback)
callback.addMessage(mes);
}

if(cd.comments!=null && !cd.comments.isEmpty() && !HtmlUtil.isValid(cd.comments)) {
cd.comments=HtmlUtil.clean(cd.comments, "UTF-8");
GinasProcessingMessage mes = GinasProcessingMessage
.WARNING_MESSAGE(
"Code '%s'[%s] code text: %s contains one or more forbidden html tags that will be removed",
cd.code, cd.codeSystem, cd.comments)
.appliableChange(true);
callback.addMessage(mes);
}

} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 1c919bf

Please sign in to comment.