defaultformatter config option ignored on new paste — hardcoded 'plaintext' in Controller.newPaste()
Bug description
The defaultformatter option in conf.php is ignored when creating a new paste.
The formatter select always defaults to plaintext regardless of the configured value.
Expected behavior
Setting defaultformatter = "markdown" in conf.php should pre-select Markdown
in the formatter dropdown when the user opens a new paste.
Actual behavior
The formatter dropdown always shows plaintext selected, even when
defaultformatter = "markdown" is correctly set and confirmed in the server-side HTML
(<option value="markdown" selected="selected">).
Root cause
In js/privatebin.js, Controller.newPaste() hardcodes the formatter to plaintext:
// js/privatebin.js ~line 5813
me.newPaste = function()
{
// ...
PasteViewer.setFormat('plaintext'); // ← ignores defaultformatter
TopNav.setFormat('plaintext'); // ← ignores defaultformatter
// ...
}These two calls override the selected="selected" attribute already correctly
rendered in the HTML by the PHP backend.
Fix
Replace the hardcoded 'plaintext' with Model.getFormatDefault(),
which reads the current value of #pasteFormatter (already set correctly
by the server-side template):
PasteViewer.setFormat(Model.getFormatDefault());
TopNav.setFormat(Model.getFormatDefault());Note: after patching privatebin.js the SRI hash in Configuration.php
must be updated accordingly.
Environment
- PrivateBin version: 2.0.4
- Image:
privatebin/nginx-fpm-alpine:latest - Browser: tested on Firefox and Chrome (multiple sessions, cleared cache)
conf.phpsetting:defaultformatter = "markdown"- Server-side HTML confirmed correct (
selected="selected"on markdown option) - No localStorage or sessionStorage interference confirmed via DevTools
Steps to reproduce
- Set
defaultformatter = "markdown"inconf.php - Open a new PrivateBin instance in the browser
- Observe the formatter dropdown shows "Plain Text" instead of "Markdown"
- Inspect the raw HTML:
<option value="markdown" selected="selected">is correct - Inspect via DevTools console:
document.querySelector('#pasteFormatter option[selected]').value→"markdown"✓document.getElementById('pasteFormatter').value→"plaintext"✗
Source: PrivateBin/PrivateBin