Escape strings

This commit is contained in:
斟酌 鵬兄 2016-03-09 23:42:55 +08:00
parent 49d9bb0f4f
commit cbd36260dc
10 changed files with 64 additions and 35 deletions

View File

@ -20,6 +20,7 @@
var XDate = __import( "Astro.utils.Date" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
var compileProp = ns[ NS_INVOKE ]( "compileProp" );
var postData = __import( "System.Net.postData" );
@ -72,8 +73,8 @@
if( override )
{
id = override.value;
title = override.title || "";
id = unescapeStr( override.value );
title = unescapeStr( override.title ) || "";
}
else
{
@ -160,7 +161,7 @@
if( opt = stage.getDAttribute( "title" ) )
{
options += " title=\"" + opt + "\"";
options += " title=\"" + escapeStr( opt ) + "\"";
}
return "[articlelink" + options + "]"

View File

@ -14,6 +14,7 @@
var MessageBox = __import( "Components.MessageBox" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
var compileProp = ns[ NS_INVOKE ]( "compileProp" );
var code = function ( insertSnippet, snippetWrap, createContext, override )
@ -99,15 +100,15 @@
).show();
}
, visualizer = function ( submitted, override )
, visualizer = function( submitted, override )
{
var lang, code, inline
, stage = this.stage;
if ( override )
if( override )
{
lang = override.lang;
code = override.value;
lang = unescapeStr( override.lang );
code = unescapeStr( override.value );
inline = override.inline;
}
else

View File

@ -13,9 +13,10 @@
/** @type {Components.MessageBox} */
var MessageBox = __import( "Components.MessageBox" );
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var footnote = function (insertSnippet, snippetWrap, createContext, override)
var footnote = function( insertSnippet, snippetWrap, createContext, override )
{
var temp, i, j
@ -38,12 +39,12 @@
).show();
}
, visualizer = function (submitted, override)
, visualizer = function( submitted, override )
{
var mText, stage = this.stage;
mText = override ? override.value : this.mText.value;
mText = override ? unescapeStr( override.value ) : this.mText.value;
if (submitted && mText)
{

View File

@ -13,6 +13,7 @@
/** @type {Components.MessageBox} */
var MessageBox = __import( "Components.MessageBox" );
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var compileProp = ns[ NS_INVOKE ]( "compileProp" );
@ -94,8 +95,8 @@
if ( override )
{
size = override.size;
heading = override.value;
size = unescapeStr( override.size );
heading = unescapeStr( override.value );
}
else
{

View File

@ -14,8 +14,9 @@
var MessageBox = __import( "Components.MessageBox" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
var html = function (insertSnippet, snippetWrap, createContext, override)
var html = function( insertSnippet, snippetWrap, createContext, override )
{
var temp, i, j
@ -38,12 +39,12 @@
).show();
}
, visualizer = function (submitted, override)
, visualizer = function( submitted, override )
{
var code, stage = this.stage;
code = override ? override.value : this.code.value;
code = override ? unescapeStr( override.value ) : this.code.value;
if (submitted && code)
{

View File

@ -13,6 +13,8 @@
/** @type {Components.MessageBox} */
var MessageBox = __import( "Components.MessageBox" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
var compileProp = ns[ NS_INVOKE ]( "compileProp" );
var image = function( insertSnippet, snippetWrap, createContext, override )
@ -61,8 +63,8 @@
if ( override )
{
src = override.value;
href = override.href;
src = unescapeStr( override.value );
href = unescapeStr( override.href );
preferred = override.preferred ? "on" : "";
}
else
@ -155,10 +157,9 @@
var element = IDOMElement( stage )
, props = [ "href", "preferred" ]
return "[img"
+ compileProp( element, props )
+ "]"
+ element.getDAttribute( "value" ) + "[/img]"
return "[img" + compileProp( element, props ) + "]"
+ escapeStr( element.getDAttribute( "value" ) )
+ "[/img]"
;
};

View File

@ -12,7 +12,10 @@
var Dand = __import( "Dandelion" );
/** @type {Components.MessageBox} */
var MessageBox = __import( "Components.MessageBox" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
var link = function(insertSnippet, snippetWrap, createContext, override)
{
var temp, i, j
@ -46,10 +49,10 @@
var src, href
, stage = this.stage;
if (override)
if( override )
{
src = override.value;
href = override.href;
src = unescapeStr( override.value );
href = unescapeStr( override.href );
}
else
{
@ -117,12 +120,12 @@
{
// [link href=\"" + this.href.value + "\"]" + text + "[/link]
var element = IDOMElement(stage)
, href = element.getDAttribute("href");
, href = escapeStr( element.getDAttribute("href") )
, val = escapeStr( element.getDAttribute("value") ) ;
return "[link" + (href ? (" href=\"" + href + "\"") : "") + "]" + element.getDAttribute("value") + "[/link]";
return "[link" + (href ? (" href=\"" + href + "\"") : "") + "]" + val + "[/link]";
};
__static_method( link, "compile", compile );
ns[ NS_EXPORT ]( EX_CLASS, "Link", link );

View File

@ -14,6 +14,8 @@
var MessageBox = __import( "Components.MessageBox" );
var compileProp = ns[ NS_INVOKE ]( "compileProp" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
var spoiler = function(insertSnippet, snippetWrap, createContext, override)
{
@ -48,15 +50,15 @@
, "OK", "Cancel", visualizer.bind({title: input_title, content:v_snippetInput, expanded: input_expanded, stage: this._stage})).show();
}
, visualizer = function (submitted, override)
, visualizer = function( submitted, override )
{
var content, title, expanded
, stage = this.stage;
if (override)
if( override )
{
content = override.value;
title = override.title;
content = unescapeStr( override.value );
title = unescapeStr( override.title );
expanded = override.expanded ? "on" : "";
}
else
@ -142,7 +144,7 @@
return "[spoiler"
+ compileProp( element, props )
+ "]"
+ element.getDAttribute( "value" )
+ escapeStr( element.getDAttribute( "value" ) )
+ "[/spoiler]";
};

View File

@ -4,7 +4,22 @@
var escapeStr = function ( str )
{
return str.replace( /\[/g, "[" ).replace( /\]/g, "]" );
if( !str ) return str;
return str
.replace( /\[/g, "[" )
.replace( /\]/g, "]" )
.replace( /"/g, """ )
;
};
var unescapeStr = function( str )
{
if( !str ) return str;
return str
.replace( /[/g, "[" )
.replace( /]/g, "]" )
.replace( /"/g, "\"" )
;
};
var compileProp = function ( _iDOM, keys )
@ -14,12 +29,13 @@
{
if( ( k = _iDOM.getDAttribute(keys[i]) ) )
{
j += " " + keys[i] + "=\"" + k + "\"";
j += " " + keys[i] + "=\"" + escapeStr( k ) + "\"";
}
}
return j;
};
ns[ NS_EXPORT ]( EX_FUNC, "escapeStr", escapeStr );
ns[ NS_EXPORT ]( EX_FUNC, "unescapeStr", unescapeStr );
ns[ NS_EXPORT ]( EX_FUNC, "compileProp", compileProp );
})();

View File

@ -3,4 +3,6 @@ Astro.Blog.AstroEdit.Visualizer.Snippet = function(){};
/** @type {Function} */
Astro.Blog.AstroEdit.Visualizer.Snippet.escapeStr;
/** @type {Function} */
Astro.Blog.AstroEdit.Visualizer.Snippet.unescapeStr;
/** @type {Function} */
Astro.Blog.AstroEdit.Visualizer.Snippet.compileProp;