Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into extra

  • Loading branch information...
commit 3956073a57d3257418059e637badaab1deba5dcc 2 parents 572596b + bb183b5
@michelf authored
Showing with 21 additions and 11 deletions.
  1. +21 −11 markdown.php
View
32 markdown.php
@@ -337,9 +337,9 @@ function stripLinkDefinitions($text) {
}
function _stripLinkDefinitions_callback($matches) {
$link_id = strtolower($matches[1]);
- $this->urls[$link_id] = $this->encodeAmpsAndAngles($matches[2]);
+ $this->urls[$link_id] = $this->encodeAttribute($matches[2]);
if (isset($matches[3]))
- $this->titles[$link_id] = str_replace('"', '"', $matches[3]);
+ $this->titles[$link_id] = $this->encodeAttribute($matches[3]);
return ''; # String that will replace the block
}
@@ -713,12 +713,12 @@ function _doAnchors_reference_callback($matches) {
if (isset($this->urls[$link_id])) {
$url = $this->urls[$link_id];
- $url = $this->encodeAmpsAndAngles($url);
+ $url = $this->encodeAttribute($url);
$result = "<a href=\"$url\"";
if ( isset( $this->titles[$link_id] ) ) {
$title = $this->titles[$link_id];
- $title = $this->encodeAmpsAndAngles($title);
+ $title = $this->encodeAttribute($title);
$result .= " title=\"$title\"";
}
@@ -737,12 +737,11 @@ function _doAnchors_inline_callback($matches) {
$url = $matches[3] == '' ? $matches[4] : $matches[3];
$title =& $matches[7];
- $url = $this->encodeAmpsAndAngles($url);
+ $url = $this->encodeAttribute($url);
$result = "<a href=\"$url\"";
if (isset($title)) {
- $title = str_replace('"', '&quot;', $title);
- $title = $this->encodeAmpsAndAngles($title);
+ $title = $this->encodeAttribute($title);
$result .= " title=\"$title\"";
}
@@ -817,7 +816,7 @@ function _doImages_reference_callback($matches) {
$link_id = strtolower($alt_text); # for shortcut links like ![this][].
}
- $alt_text = str_replace('"', '&quot;', $alt_text);
+ $alt_text = $this->encodeAttribute($alt_text);
if (isset($this->urls[$link_id])) {
$url = $this->urls[$link_id];
$result = "<img src=\"$url\" alt=\"$alt_text\"";
@@ -841,10 +840,11 @@ function _doImages_inline_callback($matches) {
$url = $matches[3] == '' ? $matches[4] : $matches[3];
$title =& $matches[7];
- $alt_text = str_replace('"', '&quot;', $alt_text);
+ $alt_text = $this->encodeAttribute($alt_text);
+ $url = $this->encodeAttribute($url);
$result = "<img src=\"$url\" alt=\"$alt_text\"";
if (isset($title)) {
- $title = str_replace('"', '&quot;', $title);
+ $title = $this->encodeAttribute($title);
$result .= " title=\"$title\""; # $title already quoted
}
$result .= $this->empty_element_suffix;
@@ -1230,6 +1230,16 @@ function formParagraphs($text) {
}
+ function encodeAttribute($text) {
+ #
+ # Encode text for a double-quoted HTML attribute.
+ #
+ $text = $this->encodeAmpsAndAngles($text);
+ $text = str_replace('"', '&quot;', $text);
+ return $text;
+ }
+
+
function encodeAmpsAndAngles($text) {
# Smart processing for ampersands and angle brackets that need to be encoded.
if ($this->no_entities) {
@@ -1270,7 +1280,7 @@ function doAutoLinks($text) {
return $text;
}
function _doAutoLinks_url_callback($matches) {
- $url = $this->encodeAmpsAndAngles($matches[1]);
+ $url = $this->encodeAttribute($matches[1]);
$link = "<a href=\"$url\">$url</a>";
return $this->hashPart($link);
}
Please sign in to comment.
Something went wrong with that request. Please try again.