2012-08-02 15 views
7

Sto usando l'editor wysihtml wysiwyg.wysihtml5. image src e href sono spogliati

Il problema è che l'attributo immagine src e l'attributo link href vengono rimossi da html. Al server sto già ottenendo l'html spogliato.

Come posso risolvere questo problema?

Sto usando il ruler advanced.js. Con tutte le regole.

Editor

UPDATE 1

Bene editor.getValue e jquery().val() for textarea dare stessi valori su modulo di invio. significa che il modulo deve essere inviato correttamente.

Ma ho visto la richiesta POST che viene inviata dal browser. ed è senza URL. Qualcosa non va.

UPDATE 2

Se rimuovo da tutto set di regole connesse con IMG, tuttavia, funziona inproperly.

UPDATE 3

In risposta al Marrowmaw commento.

Mi aspetto:

<a href="http://domain.com/" title="Link: http://domain.com">Link</a> 

Ma ho

<a href="" title="Link: Null">Link</a> 

AGGIORNAMENTO 4

<div id="wysihtml5-toolbar" style="display: none;"> 
     <button class="btn" data-wysihtml5-command="bold"> 
     {{ "Bold"|trans }} 
     </button> 
     <button class="btn" data-wysihtml5-command="italic"> 
     {{ "Italic"|trans }} 
     </button> 
     <button class="btn" data-wysihtml5-command="createLink"> 
     {{ "Link"|trans }}/{{ "Unlink"|trans }} 
     </button> 
     <button class="btn" data-wysihtml5-command="insertUnorderedList"> 
     * 
     </button> 
     <button class="btn" data-wysihtml5-command="insertOrderedList"> 
     1,2,3 
     </button> 
     <button class="btn" data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1"> 
     {{ "Heading"|trans }} 
     </button> 
     <button class="btn" data-wysihtml5-command="insertImage"> 
     {{ "Image"|trans }} 
     </button> 

     <div data-wysihtml5-dialog="createLink" style="display: none;"> 
      <label> 
      {{ "Link"|trans }}: 
      <input data-wysihtml5-dialog-field="href" value="http://"> 
      </label> 
      <a data-wysihtml5-dialog-action="save">{{ "Save"|trans }}</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">{{ "Cancel"|trans }}</a> 
     </div> 
      <!-- Dialog --> 
     <div data-wysihtml5-dialog="insertImage" style="display: none;"> 
      <label> 
      URL: <input data-wysihtml5-dialog-field="src" value="http://"> 
      </label> 
      <label> 
      Alternative text: <input data-wysihtml5-dialog-field="alt" value=""> 
      </label> 
      <label> 
       {{ "Align"|trans }}: 
       <select data-wysihtml5-dialog-field="className"> 
        <option value="">{{ "default"|trans }}</option> 
        <option value="wysiwyg-float-left">{{ "left"|trans }}</option> 
        <option value="wysiwyg-float-right">{{ "right"|trans }}</option> 
       </select> 
      </label> 
      <a data-wysihtml5-dialog-action="save">{{ "Save"|trans }}</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">{{ "Cancel"|trans }}</a> 
     </div> 
     </div> 
     <form action="{{ path('###_save_homepage') }}" method="POST" > 
     <textarea id="wysihtml5-textarea" placeholder="{{ "Enter your text"|trans }}..." autofocus name="homepage" style="width:700px;height:400px;">   
      {{ homepage|raw }}   
     </textarea> 
     <input type="submit" value="{{ "Save"|trans }}" class="btn" /> 
    </form> 

E JS init:

<script type="text/javascript"> 
jQuery(document).ready(function(){ 
    var editor = new wysihtml5.Editor("wysihtml5-textarea", { // id of textarea element 
      toolbar:  "wysihtml5-toolbar", // id of toolbar element 
      parserRules: wysihtml5ParserRules // defined in parser rules set 
     });  

    }); 

</script> 
+0

ho aggiornato il post con i dettagli –

+0

L'html viene rimosso prima che venga inviato al server o viene rimosso da qualche parte tra il client e il server? Se è il secondo, puoi sfuggire all'html prima di inviarlo e scovarlo all'altra estremità. – starbeamrainbowlabs

+0

Sembra che da qualche parte tra%) –

risposta

16

Prova a dare un'occhiata al file wysihtml5-x.x.x.js a cui fai riferimento.

Hanno deciso che avrebbero consentito solo URL assoluti (nel nome di guardia contro XSS). Il codice qui sotto essenzialmente ti consente di prendere qualsiasi valore se ti senti a tuo agio con questo trade off.

Ctrl-F per "attributeCheckMethods var" e apportare le seguenti modifiche - source:

var attributeCheckMethods = { 
url: (function() { 
    /*var REG_EXP = /^https?:\/\//i;*/ 
    return function(attributeValue) { 
    /*if (!attributeValue || !attributeValue.match(REG_EXP)) { 
     return null;*/ 
    if (!attributeValue) { 
     return ""; 
    } 
    /*return attributeValue.replace(REG_EXP, function(match) { 
     return match.toLowerCase(); 
    });*/ 

    var parser = document.createElement('a'); 
    parser.href = attributeValue; 

    if ( parser.protocol == 'http:' 
     || parser.protocol == 'https:' 
     || parser.protocol == 'ftp:' 
    ) return attributeValue; 
    }; 
})(), 
1

Il modo in cui il wysihtml5 convalida di markup è esplicitamente rigorosa. Se l'URL o SRC non convalidano, saranno omessi.

Vorrei esaminare il file parser_rules/advanced.js. È possibile rimuovere, modificare e modificare le regole che convalidano ciascun tag.

Problemi correlati