0

我正在使用 jsoup 清理用户输入的 html 代码(通常:用户忘记关闭标签)。它对新条目工作得很好,但在编辑以前的条目时没有做任何事情(已经被 jsoup 清理)。这是代码:

public void on_newMyData(Dictionary d, Attributes a, Transaction t) throws LogicException {
  sanitizeHTMLInput(d,a,t);
}
public void on_editMyData(Dictionary d, Attributes a, Transaction t) throws LogicException {
  sanitizeHTMLInput(d,a,t);
}
private void sanitizeHTMLInput(Dictionary d, Attributes a, Transaction t) throws LogicException {
  try {
    Object unsafe = a.getAttribute("answer");
    String safe = Jsoup.clean(String.valueOf(unsafe), Whitelist.relaxed());
    d.put("answer",safe);       
  } catch (AttributeNotFoundException e) {
    //if the answer is empty, no sanitizing is needed
  }
}

我做错了什么还是有我没有发现的限制?

4

0 回答 0