Bug in [code] text formatting

Started by NoCforMe, May 11, 2024, 03:29:16 PM

Previous topic - Next topic

NoCforMe

Hello; I'm from another forum (The MASM Forum) that runs on your software. Overall, it's just what the doctor ordered, and suits us fine over there.

Unfortunately, my first post here is to report a bug, or at least what appears to be a bug. It has to do with the rendering of text enclosed in [code] - [/code] tags.

Specifically: code text that contains tabs gets mangled.

A lot of us over there post code text that is tabbed, because we like things to line up nice and pretty, and it's a lot better way to do that than by inserting a bunch of spaces. (There are some who use spaces, but the majority use tabs.)

If you post code containing tabs, and immediately post your message, it's fine: the tabs are retained and render correctly.

But if you preview the post before posting it, then the tabs are replaced by spaces, and not the correct number of spaces either; the formatting is badly mangled.

This is very annoying, as you can imagine, if you want your text to retain its tabbing.  I've gotten in the habit of writing everything in the message except any code, previewing it, then adding the code at the last minute and posting it immediately.

I don't know why you would even replace tabs with spaces; it certainly uses more space, for one thing.

The fact that I can post code with tabs and have the tabs retained proves to me that your code is capable of rendering tabbed text correctly; it's just that the tabs are removed and replaced with spaces upon previewing the post.

I realize that the code involved on your side for this can't be simple, and appreciate that any fixes to this won't come overnight. But I'm hoping that someone there will look into this and see what's what.

I'll post some examples as followups to this post so you can see what's going on here.

Other than that, happy to be part of your "gang".

NoCforMe

Here's a sample of tabbed text that should render OK since I'm not going to preview it before posting:
;============================================
; HERE BE DATA
;============================================
.data

ALIGN 4
TheDialogTemplate LABEL DWORD
INCLUDE DLG_loadBitmapTest.inc

ALIGN 4

FileOpenDlgTitle DB "Select Needle Image File", 0
FileOpenStartPathStr DB ".\*."
DefaultExtension DB "BMP", 0
BMPfilters LABEL BYTE
DB "BMP files (*.bmp)", 0, "*.bmp", 0
DB "All files", 0, "*.*", 0, 0

NullString DB 0

BMPfileFmt DB "File %u", 0
LIresultFmt DB "LoadImage() result: ""%s""", 0

NoCforMe

Here's the same text but after previewing it before posting:
;============================================
; HERE BE DATA
;============================================
.data

    ALIGN 4
TheDialogTemplate    LABEL DWORD
    INCLUDE DLG_loadBitmapTest.inc

    ALIGN 4

FileOpenDlgTitle    DB "Select Needle Image File", 0
FileOpenStartPathStr    DB ".\*."
DefaultExtension    DB "BMP", 0
BMPfilters        LABEL BYTE
            DB "BMP files (*.bmp)", 0, "*.bmp", 0
            DB "All files", 0, "*.*", 0, 0

NullString        DB 0

BMPfileFmt        DB "File %u", 0
LIresultFmt        DB "LoadImage() result: ""%s""", 0

NoCforMe

BTW, here's a link to our forum (The MASM Forum) [nofollow] that I apparently wasn't allowed to post in my first post.

NoCforMe

I reported a problem that I consider a bug in your Bug Reports sub-forum. However, while the post has gotten a lot of views, there have been no replies yet. An admin at my forum (which uses your software) advised me that I should perhaps post in this sub-forum instead, so I'm doing so.

I'm a newcomer here and don't know exactly what your protocol is or what is considered a bug or not. I'm just trying to get someone to look at this problem.

I appreciate any help we can get here.

(The problem is text formatting in [code]-[/code] tags when it contains tabs.)

Thanks!

Aleksi "Lex" Kilpinen

Topics merged. Please avoid opening multiple topics on one issue. The original topic was placed correctly, and someone will look at it eventually. Please understand that we have no paid staff, everyone here is a volunteer, so sometimes things may take some time.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Sir Osis of Liver

Cannot replicate this in 2.1.4 core.  Code previews and posts correctly -

https://www.thekrashsite.com/smf21core/index.php?topic=1.0

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

NoCforMe

Quote from: Aleksi "Lex" Kilpinen on May 12, 2024, 02:22:52 PMTopics merged. Please avoid opening multiple topics on one issue. The original topic was placed correctly, and someone will look at it eventually. Please understand that we have no paid staff, everyone here is a volunteer, so sometimes things may take some time.

OK, no problemo.

Diego Andrés

test

;============================================
; HERE BE DATA
;============================================
.data

ALIGN 4
TheDialogTemplate LABEL DWORD
INCLUDE DLG_loadBitmapTest.inc

ALIGN 4

FileOpenDlgTitle DB "Select Needle Image File", 0
FileOpenStartPathStr DB ".\*."
DefaultExtension DB "BMP", 0
BMPfilters LABEL BYTE
DB "BMP files (*.bmp)", 0, "*.bmp", 0
DB "All files", 0, "*.*", 0, 0

NullString DB 0

BMPfileFmt DB "File %u", 0
LIresultFmt DB "LoadImage() result: ""%s""", 0


SMF Tricks - Free & Premium Responsive Themes for SMF.

Diego Andrés

Can't reproduce it either, tested it on other forums too.
Perhaps it's because we are grabbing this code directly from your post? Perhaps an issue with your code editor?

SMF Tricks - Free & Premium Responsive Themes for SMF.

NoCforMe

I would think the text posted in my example (the first one, not the 2nd one, since it still contains tabs) should work.

What do you mean by "my code editor": the editor I used to produce the text before posting it to my forum? That doesn't really make any difference: any ASCII text editor (Notepad, etc.) will produce text with tabs.

I'm checking with my admin to find out what version of (Simple Machines) software our forum uses; I would assume it's the latest and greatest, but that might be a wrong assumption.

The text posted below does exhibit this behavior. The original text contains tabs, but after previewing it** it now contains spaces, badly formatted:
;====================================
; WM_ERASEBKGND handler
;====================================
do_bkgnd:
    INVOKE    CreateCompatibleDC, wParam
    MOV    bmpDC, EAX
    INVOKE    GetObject, MeterBMPhandle, SIZEOF BITMAP, ADDR bm
    INVOKE    SelectObject, bmpDC, MeterBMPhandle
    INVOKE    BitBlt, wParam, 0, 0, bm.bmWidth, bm.bmHeight, bmpDC, 0, 0, SRCCOPY
    INVOKE    DeleteDC, bmpDC

true_exit:
    MOV    EAX, TRUE
    RET
** Turns out I had to click "Preview" twice to get this to happen.
Try it yourself: paste any text containing tabs into a [code]-[/code] block, then click Preview (twice) and see what happens.

Oddly enough, it didn't work (tabbed text didn't get converted to spaces) while I was composing the post; I had to modify the post after posting, perhaps because of how many times I had clicked Preview? In any case, after clicking Preview twice while editing, it did that thing, as you can see for yourself.

Definitely reproducible behavior right in this forum, so far as I can tell.

Diego Andrés

Quote from: NoCforMe on May 12, 2024, 04:35:19 PMI would think the text posted in my example (the first one, not the 2nd one, since it still contains tabs) should work.

That's what I used/did to test, using the preview button before posting.

SMF Tricks - Free & Premium Responsive Themes for SMF.

NoCforMe

Did you click Preview twice? That seems to be the magic incantation here ...

Arantor

Side question preview from quick reply or full reply? The pathways are not the same.

Separate side question: when you hit preview does the whole page reload?
Holder of controversial views, all of which my own.

NoCforMe

I'll have to reproduce my path.
In the case of editing the post, it was in the Modify message panel (or whatever you call that thing).
Will answer your other question shortly.

NoCforMe

Posted using Quick Reply:
; Register meter-display window class:
    MOV    WC.lpfnWndProc, OFFSET VUmeterProc
    MOV    EAX, DlgBkBrush
    MOV    WC.hbrBackground, EAX
    MOV    WC.lpszClassName, OFFSET VUmeterClassname
    INVOKE    LoadCursor, NULL, IDC_ARROW
    MOV    WC.hCursor, EAX
    INVOKE    RegisterClassEx, OFFSET WC
1st use of Preview: text is OK (tabs and formatting are retained).
2nd use of Preview: tabs--> spaces, formatting malformed.
The whole page refreshes when clicking Preview.


NoCforMe

Posted using Post reply:
; Register meter-display window class:
MOV WC.lpfnWndProc, OFFSET VUmeterProc
MOV EAX, DlgBkBrush
MOV WC.hbrBackground, EAX
MOV WC.lpszClassName, OFFSET VUmeterClassname
INVOKE LoadCursor, NULL, IDC_ARROW
MOV WC.hCursor, EAX
INVOKE RegisterClassEx, OFFSET WC
Preview doesn't change the formatting at all, no matter how many times I click it.
Whole pages doesn't reload.


NoCforMe

Posted using Post reply, then edited ("Modify message"):
; Register meter-display window class:
    MOV    WC.lpfnWndProc, OFFSET VUmeterProc
    MOV    EAX, DlgBkBrush
    MOV    WC.hbrBackground, EAX
    MOV    WC.lpszClassName, OFFSET VUmeterClassname
    INVOKE    LoadCursor, NULL, IDC_ARROW
    MOV    WC.hCursor, EAX
    INVOKE    RegisterClassEx, OFFSET WC
As soon as the text appears in Modify message it has been stripped of tabs and formatting is malformed. (No need to use Preview.)

Arantor

So there's actually several things going on here that the team will need to look at:

* Hitting preview from QR takes you to full reply, but full reply from this point onwards doesn't use AJAX for previews (which it should)
* Full page submission of post for preview causes some processing that it shouldn't
* Saving a page/editing is causing stripping of tabs

It's long been the case that QR submission doesn't quite behave the same as regular submission, and that bug needs to die already.

I know there's some space collapsing for multiple sequential spaces to preserve them (interleaving of U+20 and U+A0 for visual reproduction but this is sketchy for code segments) and there was always some historical drama around tab handling because historically tab handling was... broken in various browsers - because whitespace is supposed to be condensed and in this one case you explicitly don't want that.

I wonder if this could be solved now by stripping the handling for the most part around whitespace munging in the preparser and the parser and ensuring that the code bbc enforces white-space: pre, rather than the current styling (because this should really be preserved by CSS at this point rather than munging the markup in a variety of ways)
Holder of controversial views, all of which my own.

NoCforMe

Sounds to me like some progress being made. Thanks! I'll stay tuned.

Advertisement: