* Classify the type of hyperlink the destination describes. * * @param destination The hyperlink destination. * @param trusted Whether we trust the content of this file. * @return HyperlinkType The classification of the link. */
| 163 | * @return HyperlinkType The classification of the link. |
| 164 | */ |
| 165 | static HyperlinkType ClassifyHyperlink(const std::string &destination, bool trusted) |
| 166 | { |
| 167 | if (destination.empty()) return HyperlinkType::Unknown; |
| 168 | if (destination.starts_with("#")) return HyperlinkType::Internal; |
| 169 | |
| 170 | /* Only allow external / internal links for sources we trust. */ |
| 171 | if (!trusted) return HyperlinkType::Unknown; |
| 172 | |
| 173 | if (destination.starts_with("http://")) return HyperlinkType::Web; |
| 174 | if (destination.starts_with("https://")) return HyperlinkType::Web; |
| 175 | if (destination.starts_with("./")) return HyperlinkType::File; |
| 176 | return HyperlinkType::Unknown; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Create a valid slug for the anchor. |
no test coverage detected