BlogEngine VB Syntax Highlighting Shows HTML Characters

So I've found that VB syntax highlighting is broken in version 1.3 of BlogEngine.Net. If you add some VB code to a post like this:

[ code:vb ]

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.Xml
Imports System.IO
Imports System.Reflection

Public Class ScriptMain
    Inherits UserComponent

    Dim sw As StreamWriter
    Dim xWriter As XmlTextWriter
    Dim rowName As String

[ /code ]

You get output like this: 



Nice! So after some hunting through CodeFormatter.cs it looks like an HTML decode has been left out entirely. This is strange because all the other supported languages c#, javascript etc have the correct call to HtmlDecode. I'm guessing it's a genuine oversight. After editing, my CodeFormatter.cs looks like this around line 129:

private string Highlight(HighlightOptions options, string text)
{
    switch (options.Language)
    {
        case "c#":
            CSharpFormat csf = new CSharpFormat();
            csf.LineNumbers = options.DisplayLineNumbers;
            csf.Alternate = options.AlternateLineNumbers;
            return HttpContext.Current.Server.HtmlDecode(
                csf.FormatCode(text));

        case "vb":
            VisualBasicFormat vbf = new VisualBasicFormat();
            vbf.LineNumbers = options.DisplayLineNumbers;
            vbf.Alternate = options.AlternateLineNumbers;
           
            //Jimmy:call to HtmlDecode has been left out in v1.3
            //return vbf.FormatCode(text);
            return HttpContext.Current.Server.HtmlDecode(
                vbf.FormatCode(text));
   
    ...
    }
}

I re-compiled and everything was dandy. Hooray for open source.

Jimmy 

Related posts

Comments

Add comment


 

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

September 9. 2010 10:16

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010