This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 212692 - single quotes autocompletion incorrect
Summary: single quotes autocompletion incorrect
Status: RESOLVED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: HTML Editor (show other bugs)
Version: 7.2.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Marek Fukala
URL:
Keywords:
: 223787 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-05-18 09:38 UTC by Vark
Modified: 2012-12-17 12:37 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vark 2012-05-18 09:38:12 UTC
Additional auto-close quotes are being inserted when I am typing plain HTML embedded in a PHP file (but outside of a PHP block). Even if I turn off all options to put auto-quotes anywhere, I still get at least one quote added.

To reproduce:

Create a new PHP file from the default template (but it happens on any PHP file however created)

- Move beyond the closing ?>
- Type <span class= 
- Auto quotes are added ""
- Press for single quotes ' which changes both to a single quote
- Type something within the quotes
- Press ' again (to close the quote) - if you left it at double quotes, it skips the " character, but if you've changed to single quotes it both skips the character and inserts two single quotes - so you get two more than you wanted.
- If you delete the ending single quote (or turned off auto-insert ending quotes), and now press the ' single quote, you'll still get two single quotes (so one more than you wanted).

Been able to reproduce this on 7.1.1 and 7.1.2. Blanked my config directory and retried, able to reproduce.

I embed a lot of HTML within PHP files, and generally use single quotes (as in PHP I use them whenever I don't have variables to expand within a string), so this keeps catching me.
Comment 1 Ondrej Brejla 2012-05-18 13:06:30 UTC
Typing in a HTML part of a PHP file is not handled by PHP module. And imho common P3.
Comment 2 Vark 2012-05-18 21:22:08 UTC
Tested with various other file types, this same fault occurs in any HTML file (without PHP) that I create, but not in the other types I've tested (XML, plain text, CSS). It appears to be related to interpreting automatic quotes for HTML, and ignores any "turn off auto-quotes" setting I've tried.

My install is 7.1.2 PHP version, but still happens in 7.1.1 PHP version, I've not tried back further.
Comment 3 Marek Fukala 2012-05-21 13:35:45 UTC
reproducible.

<div style="|" + "'" => <div style='|' but subsequent single quote doesn't skip the generated closing one.
Comment 4 Vark 2012-07-30 00:37:50 UTC
Still problems with auto-quotes in 7.2

To reproduce (new install of 7.2 on newly installed Debian Squeeze)
- Start a PHP or HTML document
- Type <span class=
- NetBeans inserts the double quotes "|" with cursor between
- If you type text, then a ", it works properly
- If the first character you type is a ' (single quote), it will change the double quotes to a single quote '|'
- If you then type any letter, then another single quote you'll get 'x'|''

After turning off auto-quotes for HTML

- Start a PHP or HTML document
- Type <span class=
- Type a " or a '
- If you then type any letter, then another quote (double or single same as you typed to start with) you'll get 'x'|' or "x"|"
Comment 5 Vark 2012-10-24 00:46:05 UTC
Behaviour in 7.3beta, using same tests, but under different auto-completion

- If auto-quotes after = is switched off, it now does what it says (that is, nothing!)

- With Equals sign and Quote mark keypress both or either enabled

Enter <span class= then press ", a closing " will appear -> class="|"
Enter normal text, then press ", no secondary quote appears

Enter <span class=", then press ', the quotes are changed -> class='|'
Enter text that ends in a single quote, you get -> class='test''|'

Enter <span class=' -> second end quote will appear -> class='|'
Now delete the first quote, type text that ends in a quote -> class=test'|''
[Auto closing quote inserted even though we are not next to an equals sign, awkward if we are trying to use a single quote in words such as don't, won't]

With some simple testing, it's possible to keep it auto-inserting closing quotes in plenty of situations where I wouldn't expect it to (doubling single quotes within a double-quote string for example)

However, now as turning off auto-quotes completely for PHP and HTML seems to work, I've done that, and I press delete a lot less often!
Comment 6 Marek Fukala 2012-12-07 13:48:16 UTC
fixed in web-main#da6f42174e3c

I've fixed all the cases described in your last comment#5.

I will be happy if you enable the autocompletion again and give it a try in a 7.3 build. 

I'd also like to kindly ask you for other possible erroneous cases. I promise to fix them in one working day after being filed (if it happens by the 7.3 code freeze)

Thank you.
Comment 7 Vark 2012-12-07 20:08:41 UTC
Do you want me to try one of the nightlies? The last nightly I tried broke on unable to import previous settings (about 2 days ago - failed to import 7.2 settings, and didn't even find the 7.3 beta ones)

Happy to try again tho if that's what you mean
Comment 8 Quality Engineering 2012-12-08 02:57:00 UTC
Integrated into 'main-golden', will be available in build *201212080001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/da6f42174e3c
User: Marek Fukala <mfukala@netbeans.org>
Log: #212692 - single quotes autocompletion incorrect
Comment 9 Vark 2012-12-08 09:45:30 UTC
Sorry, there are still some odd things happening

Nightly 201212080001

- Installed with no prior settings imported (so default settings)
- New project created as HTML5 project, no existing sources
- After the DIV TODO entered <span class= and "|" was auto-entered as expected
- Entered test and pressed " - moved on as expected
- Pressed " again, ** Error ** Got moved unexpectedly to the next line (if you have futher content on the same line, you get moved one character along instead, then " will appear on each subsequent press)
- Moved back to first quote, deleted it, and entered a single quote ' - ** Error ** the single quote was duplicated even though there was text immediately following, got ='|'test"

- Deleted from = onwards, then pressed = again, got "|" as expected
- Pressed ' to change to single quotes - both changed as expected
- Entered test followed by a single quote - ** ERROR ** ended up with ='test'|' (final single quote duplicated, not skipped)

Created a new file of name newfile.php, from the blank file template

- Entered <?php
- Entered ?>
- Between them, four variations worked correctly - echo "test"; echo 'test'; echo "'test'"; echo '"test"'; 
- Moved to after the closing ?>
- Entered <span class=
- Automatic addition of two double quotes "|"
- Entered test followed by double quote - cursor moved to end of line
- Tried to enter an additional double quote - unable to do so at all

- Deleted from = onwards
- Retyped =, got the "|"
- Entered a single quote - got '|'
- Entered test - got 'test'
- Pressed single quote again - ** Error ** got 'test'|''

- Deleted from = onwards
- Retyped =, got the "|"
- Entered a single quote, got '|'
- Entered test - got 'test'
- Moved the cursor manually past the closing ' - got 'test'|
- Pressed single quote - ** Error ** got 'test''|'

I stopped testing at this point (i.e. have not gone through all the variations with the various auto quote settings turned off) as there still appear to be significant issues with auto quotes.

Happy to go through the variations if you want me to.
Comment 10 Marek Fukala 2012-12-10 08:52:59 UTC
> - Pressed " again, ** Error ** Got moved unexpectedly to the next line (if you
> have futher content on the same line, you get moved one character along
> instead, then " will appear on each subsequent press)
I cannot reproduce that. Could you be more specific? Ideally get empty file and make step-by-step description on a one line of code.

> - Moved back to first quote, deleted it, and entered a single quote ' - **
> Error ** the single quote was duplicated even though there was text immediately
> following, got ='|'test"
I can reproduce this - a new issue not originally reported.

As for the rest - work perfectly for me in both plain html and embedded html in php. 

It is really odd as you seem to use build with the fix. Please re-test in a latest continual dev build:

http://bertram.netbeans.org:8080/job/web-main/

You may also take a loot at the unit tests and compare it with your scenarios - the code is very straightforward.

http://hg.netbeans.org/web-main/file/79e530f5f784/html.editor/test/unit/src/org/netbeans/modules/html/editor/HtmlAutoCompletionTest.java

I'm keeping the issue opened due to the new case (='|'test") and will fix soon.

Please give it one more try in the cont. build. Thank you in advance!

> 
> - Deleted from = onwards, then pressed = again, got "|" as expected
> - Pressed ' to change to single quotes - both changed as expected
> - Entered test followed by a single quote - ** ERROR ** ended up with ='test'|'
> (final single quote duplicated, not skipped)
> 
> Created a new file of name newfile.php, from the blank file template
> 
> - Entered <?php
> - Entered ?>
> - Between them, four variations worked correctly - echo "test"; echo 'test';
> echo "'test'"; echo '"test"'; 
> - Moved to after the closing ?>
> - Entered <span class=
> - Automatic addition of two double quotes "|"
> - Entered test followed by double quote - cursor moved to end of line
> - Tried to enter an additional double quote - unable to do so at all
> 
> - Deleted from = onwards
> - Retyped =, got the "|"
> - Entered a single quote - got '|'
> - Entered test - got 'test'
> - Pressed single quote again - ** Error ** got 'test'|''
> 
> - Deleted from = onwards
> - Retyped =, got the "|"
> - Entered a single quote, got '|'
> - Entered test - got 'test'
> - Moved the cursor manually past the closing ' - got 'test'|
> - Pressed single quote - ** Error ** got 'test''|'
> 
> I stopped testing at this point (i.e. have not gone through all the variations
> with the various auto quote settings turned off) as there still appear to be
> significant issues with auto quotes.
> 
> Happy to go through the variations if you want me to.
Comment 11 Vark 2012-12-10 11:33:03 UTC
Nightly build: 201212090001 Netbeans with PHP pack - Linux (Debian Wheezy)
(will try the constant build when it has downloaded, but may not get a chance until tomorrow evening Australia/Brisbane time)

I've tried to show a more detailed step by step so you can hopefully reproduce issues

1. Installed without importing any previous settings (all defaults)
2. Create new project - PHP Application
3. Accept all defaults, no framework

4. Create new empty file - test1.php
4.1 Type <span class=
4.2 Double quotes auto-inserted - <span class="|"
4.3 Type test - <span class="test|"
4.4 Type " - cursor moves beyond closing quote - <span class="test"|
4.5 Type another " - gets duplicated - <span class="test""|" (expected single copy of character)
4.6 Moved to new line, typed " - got a single double-quote character as expected

5. Create new empty file - test2.php
5.1 Type <span class=
5.2 Double quotes auto-inserted - <span class="|"
5.3 Type a single quote, double changed to single - <span class='|'
5.4 Type test - <span class='test|'
5.5 Type single quote - cursor moved as expected - <span class='test'|
5.6 Type a single quote - gets duplicated as above - <span class='test''|'
5.7 Type a single quote on a new line - not duplicated

(If you type any single or double quote after the quotes inserted by the equals sign following the class=, without a space character between the equals and the quote, it will get duplicated, even if there are quotes already there, and it doesn't matter if its single/double quotes. Spaces within the quotes do not alter this odd behaviour, is it just looking backwards along the line to find the = without considering what's between?)

6. Create new empty file - test3.php
6.1 Type <span class=
6.2 Double quotes auto-inserted - <span class="|"
6.3 Delete the second quote - <span class="|
6.4 Type test - <span class="test|
6.5 Type a double quote - it gets duplicated - <span class="test"|" (expected only one quote)

7. Create a new empty file - test4.php
7.1 Type <span class=
7.2 Double quotes auto-inserted - <span class="|"
7.3 Delete the first quote, then try and re-insert it
7.4 End up with <span class="|"" (as noticed previously, but you don't need to enter any text to cause this to happen)

It appears there are some differences between this nightly and last nights, but still has unexpected behaviour. These tests should have reduced it to the minimum entries necessary to duplicate the behaviour.

Is there a better forum ( online) that I can live-step through these with anyone to see if it's specific to my environment, or we're just doing different steps?
Comment 12 Marek Fukala 2012-12-10 12:30:08 UTC
Thank you very much for the nice detailed description. This time even I understand it ;-)

(In reply to comment #11)
> 4.5 Type another " - gets duplicated - <span class="test""|" (expected single
> 5.5 Type single quote - cursor moved as expected - <span class='test'|
Reproducible, both are  the same issue.
> 
> 6.5 Type a double quote - it gets duplicated - <span class="test"|" (expected
Reproducible in embedded html (PHP). Works fine in plain html.

> 7.4 End up with <span class="|"" (as noticed previously, but you don't need to
Reproducible. I think in this scenario, the auto-added quote should be removed once you delete the first one.

Thank you again. I'll address these right now...
Comment 13 Marek Fukala 2012-12-10 16:54:46 UTC
all issues from comment#11 fixed in web-main#1baec6b78cb4

+ I've fixed:

<div class="|test">
press BACKASPACE
<div class=|test">
type "
<div class="|test"> instead of former <div class="|"test">

please check ideally in a web-main continual build. Thank you!
Comment 14 Quality Engineering 2012-12-13 02:38:59 UTC
Integrated into 'main-golden', will be available in build *201212130001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/1baec6b78cb4
User: Marek Fukala <mfukala@netbeans.org>
Log: #212692 - single quotes autocompletion incorrect
Comment 15 Marek Fukala 2012-12-13 15:00:23 UTC
*** Bug 223787 has been marked as a duplicate of this bug. ***
Comment 16 Vark 2012-12-13 20:51:37 UTC
Product Version: NetBeans IDE Dev (Build 201212130001)
Java: 1.7.0_09; Java HotSpot(TM) 64-Bit Server VM 23.5-b02
Runtime: Java(TM) SE Runtime Environment 1.7.0_09-b05
System: Linux version 3.2.0-4-amd64 running on amd64; UTF-8; en_AU (nb)

File - New Project - PHP5 - Defaults - No Framework

File - New file - Blank file - named test1.php

1.1 Type <span class= - auto-inserts "" - <span class="|"
1.2 Cursor back within quotes, type test and closing quote - <span class="test"| [Passed]
1.3 Type additional double quote - <span class="test""| [Passed]
1.4 Delete additional double quote, type additional single quote - <span class="test"'| [Passed]
1.5 Delete additional double quote and delete first double quote - <span class=|test"
1.6 Type double quote (to replace the first one 'accidentally' deleted) - <span class="|"test" **FAIL - double quote is duplicated when text follows**
1.7 Delete duplicated double quote, type single quote - <span class='|'test" **FAIL as above, quote duplicated despite follow text**

2.1 New blank file - test2.php
2.2 Type <span class= - auto-quotes inserted <span class=""
2.3 Type single quote - auto-quotes changed - <span class=''
2.4 Tested as above, same results (no suprise there really!)

3.1 New blank file - test3.html (NB - HTML file now)
3.2 On the automatic file, move to after </div> and create a blank line
3.3 Type <span class=, auto-quotes inserted - <span class="|"
3.4 Type test - <span class="test"
3.5 Delete and reinsert first quote with " - <span class="|test" [Passed]
3.6 Delete first quote and insert single quote - <span class='|'test" **FAIL - don't duplicate quote if text immediately following

4.1 Tools-Options-Editor-Code Completion-HTML-Turn off Equals Sign, Quote Mark
4.2 Works as expected, no auto-completions occurring

TL;DR - Works for most of the original cases correctly, and better in the HTML only version, but still duplicates quotes on the first quote character if it is deleted and reinserted. My expected behaviour would be that if there is text immediately following the " (or ') in a situation where it would try and auto-complete the quote, then the auto-complete should not occur (maybe the test is next char is not quote, and not space, suppress completion)\

Great job with all the other cases tho!
Comment 17 Marek Fukala 2012-12-13 22:47:19 UTC
Thanks lot for the detailed evaluation! I really appreciate it.

1.6 is apparently issue in the embedded PHP as this is exactly the case I fixed (and you also confirms it works in pure html in 3.5)

As for 1.7 & 3.6 - I'm not sure what should be the result and if the current behaviour is wrong at all. You already have a the text closed by the double quote and now you type a single quote. What'd you expect? <div class='test" /> ??? Doesn't seem nice to me. I'd rather prefer the closing quote to be changed to the double quote (or vice versa) or status quo.

>TL;DR - Works for most of the original cases correctly, and better in the HTML
>only version, but stil

Am I understand it right that this part refers to the expected behaviour of the 1.6,7 and 3.6 cases? I cann't figure out what TL;DR is supposed to ment. The best what came to my mind is "type left, delete right" :-)
Comment 18 Vark 2012-12-13 23:18:46 UTC
Hi,

> 1.6 is apparently issue in the embedded PHP as this is exactly the case I fixed
> (and you also confirms it works in pure html in 3.5)

It appears as an issue when the file extension/type is PHP, but there is no PHP in the file - just the HTML statement <span class= - so I wouldn't have expected it to do things differently with embedded HTML that is being recognised as a pure HTML statement, and what is does in a file with a .html extension.

I would not expect a quote to have an auto-quote appended except where there is no immediately following text, for example
<span class= (when = is pressed, add the quotes) -> <span class="|"
<span class="test", delete the first quote -> <span class=|test" -> reinsert that quote, I would expect <span class="|test" again, not <span class="|"test" which is what you get in a PHP extension file, but not in a HTML extension file

As per your next paragraph, I agree that if you are going to auto close quotes, and I type a single quote as the first character (replacing the deleted double quote), logically I would expect the closing quote to be replaced as well, and not just a duplicated single quote in front of my text

As the example

Start with - class="test"|
Delete the first quote - class=|test"
Enter a single quote - class='test"
- Current behaviour gives class='|'test"
- Expected ideal would be class='|test' (end quote changed)
- But acceptable would be class='|test" (i.e. I have to manually change the end quote)

Although identifying the end quote may be a challenge, unless you take the first un-escaped quote of the opposite type to that you are auto-completing, and I'm not certain how best to handle/identify an intermediate quote. I could see that some people would not find that as logical as I see it though.

Given I work primarily in PHP files, the current process means that to change a quote from " to ' after the rest of the line is written, I have to delete the original ", enter a ', then delete the additional ', then move to the end of the line and alter the " to ' - lots of steps

Possible enhancement request - could the default quote type inserted be selectable between " and ', often in the PHP code I'm inserting variable names, so I normally use single quotes around html attributes, not double ones.
 
> 
> >TL;DR - Works for most of the original cases correctly, and better in the HTML

Sorry - TL;DR - Too long, didn't read, so a short summary follows :)
Comment 19 Marek Fukala 2012-12-14 06:50:38 UTC
(In reply to comment #18)
> that quote, I would expect <span class="|test" again, not <span class="|"test"
> which is what you get in a PHP extension file, but not in a HTML extension file
As I already wrote, this is a clear bug, the behaviour must be consistent regardless if the html is embedded or not. Will fix today.

> Enter a single quote - class='test"
> - Current behaviour gives class='|'test"
> - Expected ideal would be class='|test' (end quote changed)
> - But acceptable would be class='|test" (i.e. I have to manually change the end
> quote)
I think I'll just do this simple variant as the proposed one with switching the opposite quotes may may not be easy with respect to the possibly contained escaped or unescaped quotes in the attribute value.

> Possible enhancement request - could the default quote type inserted be
> selectable between " and ', often in the PHP code I'm inserting variable names,
> so I normally use single quotes around html attributes, not double ones.
+1

I think it could also make the quotes autocompletion bit more "intelligent" so it you type:

<div class| + "=" => <div class="|" + "'" => <div class='|' ... then next time the single quote can be autocompleted and vice versa. It can also look at the already existing tags in the context and check the quote type and use it. All the heuristics then could be configured in the options.
Comment 20 Marek Fukala 2012-12-14 10:02:54 UTC
(In reply to comment #19)
> (In reply to comment #18)
> > that quote, I would expect <span class="|test" again, not <span class="|"test"
> > which is what you get in a PHP extension file, but not in a HTML extension file
> As I already wrote, this is a clear bug, the behaviour must be consistent
> regardless if the html is embedded or not. Will fix today.
> 
> > Enter a single quote - class='test"
> > - Current behaviour gives class='|'test"
> > - Expected ideal would be class='|test' (end quote changed)
> > - But acceptable would be class='|test" (i.e. I have to manually change the end
> > quote)
> I think I'll just do this simple variant as the proposed one with switching the
> opposite quotes may may not be easy with respect to the possibly contained
> escaped or unescaped quotes in the attribute value.
both issues above fixed in web-main#e86d19d8a760
Comment 21 Marek Fukala 2012-12-14 10:26:45 UTC
> I think it could also make the quotes autocompletion bit more "intelligent" so
> it you type:
> 
> <div class| + "=" => <div class="|" + "'" => <div class='|' ... then next time
> the single quote can be autocompleted and vice versa. It can also look at the
> already existing tags in the context and check the quote type and use it. All
> the heuristics then could be configured in the options.
done as well:

changeset:   242582:d2a3996369f7
summary:     #212692 - adjusting the autocompleted quote type after EQ in a tag
Comment 22 Marek Fukala 2012-12-14 10:29:26 UTC
> changeset:   242582:d2a3996369f7
> summary:     #212692 - adjusting the autocompleted quote type after EQ in a tag

BTW the quote type is not remembered in a settings so it lives per JVM session. I plan to make it a setting and expose it in the options UI in 7.3.next: Bug 223836 - Html completion options - ability to change the autocompleted quote type
Comment 23 Quality Engineering 2012-12-17 12:37:50 UTC
Integrated into 'main-golden', will be available in build *201212170919* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/e86d19d8a760
User: Marek Fukala <mfukala@netbeans.org>
Log: #212692 - addressing issues from comment#18