Announcement

Collapse
No announcement yet.

BBCode [CODE]c source code[/CODE]

Collapse
This topic has been answered.
X
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

    BBCode [CODE]c source code[/CODE]

    When using HTML On in a post you will get strange behaviour for the following code tag

    Code:
    // Header file for input output functions
    #include <stdio.h>
    
    // Main function: entry point for execution
    int main() {
    
        // Writing print statement to print hello world
        printf("Hello World");
    
        return 0;
    }
    In my case only this is shown:

    Click image for larger version  Name:	image.png Views:	0 Size:	12.9 KB ID:	33843

    So "<stdio.h>" is missing, although it is still there. This cannot be reproduced here on vbmods.rock since HTML On is not allowed for regular users.

    It seems that vBulletin interpretes HTML also inside the code tag, what shouldn't happen in my opinion.

    Any suggestions or comments?​
  • Answer selected by flohse at 03-08-2026, 08:39 AM.

    Try this temporary solution while waiting for the official fix by vBulletin. The solution requires editing existing PHP file, which means you'll have to re-apply this after every forum upgrade as it'll get overwritten.

    Add this line in <vB root directory>/includes/vb5/template/bbcode.php:
    PHP Code:
    // Escape < to &lt; to prevent it from being treated as HTML
    $code = str_replace('<', '&lt;', $code);

    Locate the handle_bbcode_code function and add the above code right below this line:
    PHP Code:
    $code = str_replace(['<br>', '<br />'], ['', ''], $code); 
    

    Final result:
    PHP Code:
    $code = str_replace(['<br>', '<br />'], ['', ''], $code);
    
    // Escape < to &lt; to prevent it from being treated as HTML
    $code = str_replace('<', '&lt;', $code);
    Last edited by glennrocksvb; 03-07-2026, 12:59 PM.

    Comment


      #2
      I have asked this on vbulletin.com and got the following answer from Wayne Luke.

      The system is processing the unknown HTML of <stdio.h> and the browser is processing it as HTML. vBulletin isn't altering the code. It seems that the definition in of the <pre> tag changed along the way so that code can be interpreted inside it. No C code is being interpreted or processed. The only workaround that I have at this time is to replace < and > with &lt; and &gt; respectively.

      Though, I also consider this a bug and the system should perform these replacements automatically if HTML is enabled.
      I also kindly asked him to bring this to their bugtracker.​

      Comment


        #3
        I'm posting this while HTML is on.
        Code:
        // Header file for input output functions
        #include 
        
        // Main function: entry point for execution
        int main() {
        
            // Writing print statement to print hello world
            printf("Hello World");
        
            return 0;
        }
        Last edited by glennrocksvb; 03-02-2026, 11:09 PM.
        Buy me a coffeePayPal QR Code
        My Amazon Affiliate Link
        Fast vBulletin VPS Host:
        This site is hosted by IONOS

        Comment


        • glennrocksvb
          commented
          Editing a comment
          I can confirm the issue is reproducible when HTML is on.

        #4
        Try this temporary solution while waiting for the official fix by vBulletin. The solution requires editing existing PHP file, which means you'll have to re-apply this after every forum upgrade as it'll get overwritten.

        Add this line in <vB root directory>/includes/vb5/template/bbcode.php:
        PHP Code:
        // Escape < to &lt; to prevent it from being treated as HTML
        $code = str_replace('<', '&lt;', $code);

        Locate the handle_bbcode_code function and add the above code right below this line:
        PHP Code:
        $code = str_replace(['<br>', '<br />'], ['', ''], $code); 
        

        Final result:
        PHP Code:
        $code = str_replace(['<br>', '<br />'], ['', ''], $code);
        
        // Escape < to &lt; to prevent it from being treated as HTML
        $code = str_replace('<', '&lt;', $code);
        Last edited by glennrocksvb; 03-07-2026, 12:59 PM.
        Buy me a coffeePayPal QR Code
        My Amazon Affiliate Link
        Fast vBulletin VPS Host:
        This site is hosted by IONOS

        Comment


          #5
          I also needed to replace the closing mark as well to make this finally work.

          change function handle_bbcode_code in includes/vb5/template/bbcode.php

          from
          PHP Code:
                  function handle_bbcode_code($code)
                  {
                          // remove unnecessary line breaks and escaped quotes
                          $code = str_replace(['<br>', '<br />'], ['', ''], $code);
          
                          $code = $this->stripFrontBackWhitespace($code, 1);
          

          to
          PHP Code:
                  function handle_bbcode_code($code)
                  {
                          // remove unnecessary line breaks and escaped quotes
                          $code = str_replace(['<br>', '<br />'], ['', ''], $code);
          
                          // Escape < to &lt; to prevent it from being treated as HTML
                          $code = str_replace('<', '&lt;', $code);
                          
                          // Escape > to &gt; to prevent it from being treated as HTML
                          $code = str_replace('>', '&gt;', $code);
          
                          $code = $this->stripFrontBackWhitespace($code, 1);
          

          Comment


          • flohse
            commented
            Editing a comment
            I verified a second time. The second replace is not necessary!

          #6
          You could but you don't have to. Replacing just the < should prevent it from rendering as HTML tag. Having &lt; div> will not render as <div>
          Buy me a coffeePayPal QR Code
          My Amazon Affiliate Link
          Fast vBulletin VPS Host:
          This site is hosted by IONOS

          Comment


            #7
            You're right. I don't know, I can't reproduce it anymore.

            Comment

            Latest Posts

            Collapse

            Working...
            X
            Searching...Please wait.
            An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

            Please push the back button and reload the previous window.'
            An unexpected error was returned: 'Your submission could not be processed because the token has expired.

            Please push the back button and reload the previous window.'
            An internal error has occurred and the module cannot be displayed.
            There are no results that meet this criteria.
            Search Result for "|||"